Skip to content

Commit 2360efd

Browse files
committed
ISSUE-5021 fixed guest checkout for custom shipping carrier with underscores
1 parent 5498231 commit 2360efd

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ private function limitShippingCarrier(Quote $quote) : void
190190
{
191191
$shippingAddress = $quote->getShippingAddress();
192192
if ($shippingAddress && $shippingAddress->getShippingMethod()) {
193-
$shippingDataArray = explode('_', $shippingAddress->getShippingMethod());
194-
$shippingCarrier = array_shift($shippingDataArray);
195-
$shippingAddress->setLimitCarrier($shippingCarrier);
193+
$shippingRate = $shippingAddress->getShippingRateByCode($shippingAddress->getShippingMethod());
194+
$shippingAddress->setLimitCarrier($shippingRate->getCarrier());
196195
}
197196
}
198197
}

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)