From 1036496493fbb9e771662718918ecf29f75bdf6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Ortol=C3=A1=20Ankum?= Date: Tue, 11 Jun 2024 09:41:58 +0200 Subject: [PATCH 1/4] #38811: Collect shipping rates with totals collection --- .../InstantPurchase/Model/QuoteManagement/QuoteCreation.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/InstantPurchase/Model/QuoteManagement/QuoteCreation.php b/app/code/Magento/InstantPurchase/Model/QuoteManagement/QuoteCreation.php index 4db9c86f7184e..513b35700cc3d 100644 --- a/app/code/Magento/InstantPurchase/Model/QuoteManagement/QuoteCreation.php +++ b/app/code/Magento/InstantPurchase/Model/QuoteManagement/QuoteCreation.php @@ -57,9 +57,11 @@ public function createQuote( $quote->setCustomer($customer->getDataModel()); $quote->setCustomerIsGuest(0); $quote->getShippingAddress() - ->importCustomerAddressData($shippingAddress->getDataModel()); + ->importCustomerAddressData($shippingAddress->getDataModel()) + ->setCollectShippingRates(true); $quote->getBillingAddress() - ->importCustomerAddressData($billingAddress->getDataModel()); + ->importCustomerAddressData($billingAddress->getDataModel()) + ->setCollectShippingRates(true); $quote->setInventoryProcessed(false); return $quote; } From 1c931b9672600ff0c4b32cc414f0ce5006f229d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Ortol=C3=A1=20Ankum?= Date: Tue, 11 Jun 2024 09:58:38 +0200 Subject: [PATCH 2/4] #38811: Leverage pre-collected rates when determining cheapest shipping --- .../CheapestMethodDeferredChooser.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php b/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php index 39d12668a2a21..e248dc175b19e 100644 --- a/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php +++ b/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php @@ -20,10 +20,7 @@ class CheapestMethodDeferredChooser implements DeferredShippingMethodChooserInte */ public function choose(Address $address) { - $address->setCollectShippingRates(true); - $address->collectShippingRates(); - $shippingRates = $address->getAllShippingRates(); - + $shippingRates = $this->getShippingRates($address); if (empty($shippingRates)) { return null; } @@ -32,6 +29,22 @@ public function choose(Address $address) return $cheapestRate->getCode(); } + /** + * Retrieves previously collected shipping rates or computes new ones. + * + * @param Address $address + * @return Rate[] + */ + private function getShippingRates(Address $address) : array { + if (!empty($shippingRates = $address->getAllShippingRates())) { + // Favour previously collected rates over recomputing. + return $shippingRates; + } + $address->setCollectShippingRates(true); + $address->collectShippingRates(); + return $address->getAllShippingRates(); + } + /** * Selects shipping price with minimal price. * From 37325b06b3cf18fdd7b7b05689b360bd150d6f32 Mon Sep 17 00:00:00 2001 From: glo17720 Date: Wed, 10 Jul 2024 13:26:56 +0530 Subject: [PATCH 3/4] AC-12119:: Instant purchase 'cheapest shipping' broken for configurable products --- .../ShippingMethodChoose/CheapestMethodDeferredChooser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php b/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php index e248dc175b19e..93fe609586938 100644 --- a/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php +++ b/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php @@ -13,7 +13,7 @@ */ class CheapestMethodDeferredChooser implements DeferredShippingMethodChooserInterface { - const METHOD_CODE = 'cheapest'; + public const METHOD_CODE = 'cheapest'; /** * @inheritdoc From 64c831d8eae34ac9e710fe319f8a28f074df2623 Mon Sep 17 00:00:00 2001 From: glo17720 Date: Wed, 10 Jul 2024 15:14:35 +0530 Subject: [PATCH 4/4] AC-12119:: Instant purchase 'cheapest shipping' broken for configurable products --- .../ShippingMethodChoose/CheapestMethodDeferredChooser.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php b/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php index 93fe609586938..9df58eddac55e 100644 --- a/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php +++ b/app/code/Magento/InstantPurchase/Model/ShippingMethodChoose/CheapestMethodDeferredChooser.php @@ -35,7 +35,8 @@ public function choose(Address $address) * @param Address $address * @return Rate[] */ - private function getShippingRates(Address $address) : array { + private function getShippingRates(Address $address) : array + { if (!empty($shippingRates = $address->getAllShippingRates())) { // Favour previously collected rates over recomputing. return $shippingRates;