Skip to content

Commit

Permalink
Merge pull request #9076 from magento-gl/spartans_pr_11072024_AC-12119
Browse files Browse the repository at this point in the history
[Spartans] Bugfix Delivery
  • Loading branch information
2 parents cf65863 + e96ca55 commit 29fe909
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@
*/
class CheapestMethodDeferredChooser implements DeferredShippingMethodChooserInterface
{
const METHOD_CODE = 'cheapest';
public const METHOD_CODE = 'cheapest';

/**
* @inheritdoc
*/
public function choose(Address $address)
{
$address->setCollectShippingRates(true);
$address->collectShippingRates();
$shippingRates = $address->getAllShippingRates();

$shippingRates = $this->getShippingRates($address);
if (empty($shippingRates)) {
return null;
}
Expand All @@ -32,6 +29,23 @@ 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.
*
Expand Down

0 comments on commit 29fe909

Please sign in to comment.