Skip to content

Commit bffe14c

Browse files
authored
ENGCOM-4687: [Backport] ISSUE-5021 fixed guest checkout with custom shipping carrier with underscores #21340
2 parents 77de966 + 08016a9 commit bffe14c

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

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

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

1515
/**
16+
* Guest payment information management model.
17+
*
1618
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1719
*/
1820
class GuestPaymentInformationManagement implements \Magento\Checkout\Api\GuestPaymentInformationManagementInterface
@@ -65,7 +67,7 @@ class GuestPaymentInformationManagement implements \Magento\Checkout\Api\GuestPa
6567
* @param \Magento\Checkout\Api\PaymentInformationManagementInterface $paymentInformationManagement
6668
* @param \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory
6769
* @param CartRepositoryInterface $cartRepository
68-
* @param ResourceConnection|null
70+
* @param ResourceConnection $connectionPool
6971
* @codeCoverageIgnore
7072
*/
7173
public function __construct(
@@ -87,7 +89,7 @@ public function __construct(
8789
}
8890

8991
/**
90-
* {@inheritDoc}
92+
* @inheritdoc
9193
*/
9294
public function savePaymentInformationAndPlaceOrder(
9395
$cartId,
@@ -128,7 +130,7 @@ public function savePaymentInformationAndPlaceOrder(
128130
}
129131

130132
/**
131-
* {@inheritDoc}
133+
* @inheritdoc
132134
*/
133135
public function savePaymentInformation(
134136
$cartId,
@@ -155,7 +157,7 @@ public function savePaymentInformation(
155157
}
156158

157159
/**
158-
* {@inheritDoc}
160+
* @inheritdoc
159161
*/
160162
public function getPaymentInformation($cartId)
161163
{
@@ -189,9 +191,8 @@ private function limitShippingCarrier(Quote $quote)
189191
{
190192
$shippingAddress = $quote->getShippingAddress();
191193
if ($shippingAddress && $shippingAddress->getShippingMethod()) {
192-
$shippingDataArray = explode('_', $shippingAddress->getShippingMethod());
193-
$shippingCarrier = array_shift($shippingDataArray);
194-
$shippingAddress->setLimitCarrier($shippingCarrier);
194+
$shippingRate = $shippingAddress->getShippingRateByCode($shippingAddress->getShippingMethod());
195+
$shippingAddress->setLimitCarrier($shippingRate->getCarrier());
195196
}
196197
}
197198
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,11 @@ private function getMockForAssignBillingAddress($cartId, $billingAddressMock)
280280
$billingAddressId = 1;
281281
$quote = $this->createMock(Quote::class);
282282
$quoteBillingAddress = $this->createMock(Address::class);
283+
$shippingRate = $this->createPartialMock(\Magento\Quote\Model\Quote\Address\Rate::class, []);
284+
$shippingRate->setCarrier('flatrate');
283285
$quoteShippingAddress = $this->createPartialMock(
284286
Address::class,
285-
['setLimitCarrier', 'getShippingMethod']
287+
['setLimitCarrier', 'getShippingMethod', 'getShippingRateByCode']
286288
);
287289
$this->cartRepositoryMock->method('getActive')
288290
->with($cartId)
@@ -302,6 +304,9 @@ private function getMockForAssignBillingAddress($cartId, $billingAddressMock)
302304
$quote->expects($this->once())
303305
->method('setBillingAddress')
304306
->with($billingAddressMock);
307+
$quoteShippingAddress->expects($this->any())
308+
->method('getShippingRateByCode')
309+
->willReturn($shippingRate);
305310
$quote->expects($this->once())
306311
->method('setDataChanges')
307312
->willReturnSelf();

0 commit comments

Comments
 (0)