diff --git a/Helper/Checkout.php b/Helper/Checkout.php index 5ae6f6e5..02f9e535 100755 --- a/Helper/Checkout.php +++ b/Helper/Checkout.php @@ -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; @@ -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') ?? ''); /** @@ -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 { diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php index b90593d8..974a9d91 100644 --- a/Model/Quote/Checkout.php +++ b/Model/Quote/Checkout.php @@ -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'])) {