Skip to content

Commit 29fe909

Browse files
Merge pull request #9076 from magento-gl/spartans_pr_11072024_AC-12119
[Spartans] Bugfix Delivery
2 parents cf65863 + e96ca55 commit 29fe909

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

app/code/Magento/InstantPurchase/Model/QuoteManagement/QuoteCreation.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ public function createQuote(
5757
$quote->setCustomer($customer->getDataModel());
5858
$quote->setCustomerIsGuest(0);
5959
$quote->getShippingAddress()
60-
->importCustomerAddressData($shippingAddress->getDataModel());
60+
->importCustomerAddressData($shippingAddress->getDataModel())
61+
->setCollectShippingRates(true);
6162
$quote->getBillingAddress()
62-
->importCustomerAddressData($billingAddress->getDataModel());
63+
->importCustomerAddressData($billingAddress->getDataModel())
64+
->setCollectShippingRates(true);
6365
$quote->setInventoryProcessed(false);
6466
return $quote;
6567
}

app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@
1313
*/
1414
class CheapestMethodDeferredChooser implements DeferredShippingMethodChooserInterface
1515
{
16-
const METHOD_CODE = 'cheapest';
16+
public const METHOD_CODE = 'cheapest';
1717

1818
/**
1919
* @inheritdoc
2020
*/
2121
public function choose(Address $address)
2222
{
23-
$address->setCollectShippingRates(true);
24-
$address->collectShippingRates();
25-
$shippingRates = $address->getAllShippingRates();
26-
23+
$shippingRates = $this->getShippingRates($address);
2724
if (empty($shippingRates)) {
2825
return null;
2926
}
@@ -32,6 +29,23 @@ public function choose(Address $address)
3229
return $cheapestRate->getCode();
3330
}
3431

32+
/**
33+
* Retrieves previously collected shipping rates or computes new ones.
34+
*
35+
* @param Address $address
36+
* @return Rate[]
37+
*/
38+
private function getShippingRates(Address $address) : array
39+
{
40+
if (!empty($shippingRates = $address->getAllShippingRates())) {
41+
// Favour previously collected rates over recomputing.
42+
return $shippingRates;
43+
}
44+
$address->setCollectShippingRates(true);
45+
$address->collectShippingRates();
46+
return $address->getAllShippingRates();
47+
}
48+
3549
/**
3650
* Selects shipping price with minimal price.
3751
*

0 commit comments

Comments
 (0)