Skip to content

Commit df24332

Browse files
authored
ENGCOM-4237: ISSUE-5021 fixed guest checkout with custom shipping carrier with unde… #19505
2 parents 588a293 + 84355a6 commit df24332

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Magento\Quote\Model\Quote;
1515

1616
/**
17+
* Guest payment information management model.
18+
*
1719
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1820
*/
1921
class GuestPaymentInformationManagement implements \Magento\Checkout\Api\GuestPaymentInformationManagementInterface
@@ -66,7 +68,7 @@ class GuestPaymentInformationManagement implements \Magento\Checkout\Api\GuestPa
6668
* @param \Magento\Checkout\Api\PaymentInformationManagementInterface $paymentInformationManagement
6769
* @param \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory
6870
* @param CartRepositoryInterface $cartRepository
69-
* @param ResourceConnection|null
71+
* @param ResourceConnection $connectionPool
7072
* @codeCoverageIgnore
7173
*/
7274
public function __construct(
@@ -88,7 +90,7 @@ public function __construct(
8890
}
8991

9092
/**
91-
* {@inheritDoc}
93+
* @inheritdoc
9294
*/
9395
public function savePaymentInformationAndPlaceOrder(
9496
$cartId,
@@ -129,7 +131,7 @@ public function savePaymentInformationAndPlaceOrder(
129131
}
130132

131133
/**
132-
* {@inheritDoc}
134+
* @inheritdoc
133135
*/
134136
public function savePaymentInformation(
135137
$cartId,
@@ -156,7 +158,7 @@ public function savePaymentInformation(
156158
}
157159

158160
/**
159-
* {@inheritDoc}
161+
* @inheritdoc
160162
*/
161163
public function getPaymentInformation($cartId)
162164
{
@@ -190,9 +192,8 @@ private function limitShippingCarrier(Quote $quote) : void
190192
{
191193
$shippingAddress = $quote->getShippingAddress();
192194
if ($shippingAddress && $shippingAddress->getShippingMethod()) {
193-
$shippingDataArray = explode('_', $shippingAddress->getShippingMethod());
194-
$shippingCarrier = array_shift($shippingDataArray);
195-
$shippingAddress->setLimitCarrier($shippingCarrier);
195+
$shippingRate = $shippingAddress->getShippingRateByCode($shippingAddress->getShippingMethod());
196+
$shippingAddress->setLimitCarrier($shippingRate->getCarrier());
196197
}
197198
}
198199
}

app/code/Magento/Checkout/Test/Unit/Model/GuestPaymentInformationManagementTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function testSavePaymentInformationAndPlaceOrderWithLocalizedException()
273273
*/
274274
private function getMockForAssignBillingAddress(
275275
int $cartId,
276-
\PHPUnit_Framework_MockObject_MockObject $billingAddressMock
276+
\PHPUnit_Framework_MockObject_MockObject $billingAddressMock
277277
) : void {
278278
$quoteIdMask = $this->createPartialMock(QuoteIdMask::class, ['getQuoteId', 'load']);
279279
$this->quoteIdMaskFactoryMock->method('create')
@@ -287,9 +287,11 @@ private function getMockForAssignBillingAddress(
287287
$billingAddressId = 1;
288288
$quote = $this->createMock(Quote::class);
289289
$quoteBillingAddress = $this->createMock(Address::class);
290+
$shippingRate = $this->createPartialMock(\Magento\Quote\Model\Quote\Address\Rate::class, []);
291+
$shippingRate->setCarrier('flatrate');
290292
$quoteShippingAddress = $this->createPartialMock(
291293
Address::class,
292-
['setLimitCarrier', 'getShippingMethod']
294+
['setLimitCarrier', 'getShippingMethod', 'getShippingRateByCode']
293295
);
294296
$this->cartRepositoryMock->method('getActive')
295297
->with($cartId)
@@ -309,6 +311,9 @@ private function getMockForAssignBillingAddress(
309311
$quote->expects($this->once())
310312
->method('setBillingAddress')
311313
->with($billingAddressMock);
314+
$quoteShippingAddress->expects($this->any())
315+
->method('getShippingRateByCode')
316+
->willReturn($shippingRate);
312317
$quote->expects($this->once())
313318
->method('setDataChanges')
314319
->willReturnSelf();

0 commit comments

Comments
 (0)