Skip to content

Commit

Permalink
fix(checkout): update shipping price in delivery options on change
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanveen committed Jun 10, 2024
1 parent cc660c1 commit 73d58cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
40 changes: 12 additions & 28 deletions Helper/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Quote\Api\Data\EstimateAddressInterfaceFactory;
use Magento\Quote\Model\Cart\ShippingMethod;
use Magento\Quote\Model\ShippingMethodManagement;
use MyParcelNL\Magento\Model\Rate\Result;
use MyParcelNL\Magento\Model\Source\PriceDeliveryOptionsView;
Expand Down Expand Up @@ -108,44 +109,27 @@ public function setBasePrice($base_price)
/**
* Set shipping base price
*
* @param \Magento\Quote\Model\Quote $quoteId
*
* @param int $quoteId
* @param array $forAddress
* @return Checkout
*/
public function setBasePriceFromQuote($quoteId)
public function setBasePriceFromQuote(int $quoteId, array $forAddress = []): Checkout
{
$price = $this->getParentRatePriceFromQuote($quoteId);
$method = $this->getParentRateFromQuote($quoteId, $forAddress);
$price = ($method) ? $method->getPriceInclTax() : 0;

$this->setBasePrice((double) $price);

return $this;
}

/**
* @param \Magento\Quote\Model\Quote $quoteId
*
* @return string
*/
public function getParentRatePriceFromQuote($quoteId)
{
$method = $this->getParentRateFromQuote($quoteId);
if ($method === null) {
return null;
}

return $method->getPriceInclTax();
}

/**
* @param \Magento\Quote\Model\Quote $quoteId
*
* @return \Magento\Quote\Model\Cart\ShippingMethod|null
* @param int $quoteId
* @param array $forAddress
* @return ShippingMethod|null
*/
public function getParentRateFromQuote($quoteId, array $forAddress = [])
public function getParentRateFromQuote(int $quoteId, array $forAddress = [])
{
if (null === $quoteId) {
return null;
}

$parentCarriers = explode(',', $this->getGeneralConfig('shipping_methods/methods') ?? '');

/**
Expand Down Expand Up @@ -185,7 +169,7 @@ private function getEstimatedAddress(
$address = $this->estimatedAddressFactory->create();

if (isset($fromClient['countryId'])) {
$address->setCountryId($fromClient['countryId'] ?? self::DEFAULT_COUNTRY_CODE);
$address->setCountryId($fromClient['countryId']);
$address->setPostcode($fromClient['postcode'] ?? '');
$address->setRegion($fromClient['region'] ?? '');
} else {
Expand Down
2 changes: 1 addition & 1 deletion Model/Quote/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct(
*/
public function getDeliveryOptions(array $forAddress = []): array
{
$this->helper->setBasePriceFromQuote($this->quoteId);
$this->helper->setBasePriceFromQuote((int) $this->quoteId, $forAddress);
$this->hideDeliveryOptionsForProduct();

if (isset($forAddress['countryId'])) {
Expand Down

0 comments on commit 73d58cb

Please sign in to comment.