Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(checkout): update shipping price in delivery options on change #846

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
FlorianSDV marked this conversation as resolved.
Show resolved Hide resolved
$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