Skip to content

Commit 1c931b9

Browse files
committed
#38811: Leverage pre-collected rates when determining cheapest shipping
1 parent 1036496 commit 1c931b9

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class CheapestMethodDeferredChooser implements DeferredShippingMethodChooserInte
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,22 @@ 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+
if (!empty($shippingRates = $address->getAllShippingRates())) {
40+
// Favour previously collected rates over recomputing.
41+
return $shippingRates;
42+
}
43+
$address->setCollectShippingRates(true);
44+
$address->collectShippingRates();
45+
return $address->getAllShippingRates();
46+
}
47+
3548
/**
3649
* Selects shipping price with minimal price.
3750
*

0 commit comments

Comments
 (0)