From 0cebcafef6a53a9870c4acd866e67308b65ed74a Mon Sep 17 00:00:00 2001 From: jochemgravendeel Date: Thu, 7 Nov 2024 14:28:59 +0100 Subject: [PATCH 01/10] feat: add delivery fee --- Helper/Checkout.php | 4 +--- Model/Quote/Checkout.php | 3 +++ etc/adminhtml/system.xml | 9 +++++++++ etc/config.xml | 6 ++++++ view/frontend/web/js/view/delivery-options.js | 1 + 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Helper/Checkout.php b/Helper/Checkout.php index ca1610e2..978202f5 100755 --- a/Helper/Checkout.php +++ b/Helper/Checkout.php @@ -195,13 +195,12 @@ private function getEstimatedAddress( public function getMethodPrice(string $carrier, string $key, bool $addBasePrice = true): float { $value = (float) $this->getCarrierConfig($key, $carrier); + file_put_contents('/Applications/MAMP/htdocs/MagentoNL/var/log/joeri.log', "$value $carrier $key\n",FILE_APPEND); $showTotalPrice = $this->getCarrierConfig('shipping_methods/delivery_options_prices', Data::XML_PATH_GENERAL) === PriceDeliveryOptionsView::TOTAL; - if ($showTotalPrice && $addBasePrice) { // Calculate value $value = (float) $this->getBasePrice() + $value; } - return $value; } @@ -234,7 +233,6 @@ public function getCarrierConfig(string $code, string $carrier) $this->_logger->critical('Can\'t get setting with path:' . $carrier . $code); return 0; } - return $value; } diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php index e0a1210d..d9602eab 100644 --- a/Model/Quote/Checkout.php +++ b/Model/Quote/Checkout.php @@ -207,6 +207,8 @@ private function getDeliveryData(?string $packageType = null): array } $basePrice = $this->helper->getBasePrice(); + $deliveryFee = $this->helper->getMethodPrice($carrierPath, 'delivery/delivery_fee', false); + $basePrice += $deliveryFee; $mondayFee = $canHaveMonday ? $this->helper->getMethodPrice($carrierPath, 'delivery/monday_fee') : 0; $morningFee = $canHaveMorning ? $this->helper->getMethodPrice($carrierPath, 'morning/fee') : 0; $eveningFee = $canHaveEvening ? $this->helper->getMethodPrice($carrierPath, 'evening/fee') : 0; @@ -247,6 +249,7 @@ private function getDeliveryData(?string $packageType = null): array 'priceReceiptCode' => $receiptCodeFee, 'priceOnlyRecipient' => $onlyRecipientFee, 'priceStandardDelivery' => $showTotalPrice ? $basePrice : 0, + 'priceDeliveryFee' => $deliveryFee, 'priceMondayDelivery' => $mondayFee, 'priceMorningDelivery' => $morningFee, 'priceEveningDelivery' => $eveningFee, diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 4726743b..afdca610 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -230,6 +230,15 @@ Magento\Config\Model\Config\Source\Yesno + + + validate-number + Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + This will be added to or subtracted from the regular shipping price + + 1 + + diff --git a/etc/config.xml b/etc/config.xml index fdcaf32d..21c2fe2e 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -63,6 +63,7 @@ No 1 0 + 0 14 @@ -119,6 +120,7 @@ 0 0 0 + 0 14 @@ -156,6 +158,7 @@ 0 0 0 + 0 14 @@ -176,6 +179,7 @@ 0 0 0 + 0 14 @@ -196,6 +200,7 @@ + 0 3 @@ -212,6 +217,7 @@ + 0 3 diff --git a/view/frontend/web/js/view/delivery-options.js b/view/frontend/web/js/view/delivery-options.js index 82366ffd..ba02c5b2 100644 --- a/view/frontend/web/js/view/delivery-options.js +++ b/view/frontend/web/js/view/delivery-options.js @@ -64,6 +64,7 @@ define( */ methodCodeDeliveryOptionsConfigMap: { 'myparcelnl_magento_postnl_settings/delivery': 'config.carrierSettings.postnl.priceStandardDelivery', + 'myparcelnl_magento_postnl_settings/delivery_fee': 'config.carrierSettings.postnl.priceDeliveryFee', 'myparcelnl_magento_postnl_settings/mailbox': 'config.carrierSettings.postnl.pricePackageTypeMailbox', 'myparcelnl_magento_postnl_settings/package_small': 'config.carrierSettings.postnl.pricePackageTypePackageSmall', 'myparcelnl_magento_postnl_settings/digital_stamp': 'config.carrierSettings.postnl.pricePackageTypeDigitalStamp', From 39b03f5a1df224f0759b3f1f09ce1d42c3140ac9 Mon Sep 17 00:00:00 2001 From: jochemgravendeel Date: Thu, 7 Nov 2024 15:57:48 +0100 Subject: [PATCH 02/10] feat: add delivery fee --- Helper/Checkout.php | 1 - Model/Quote/Checkout.php | 3 +-- Model/Rate/Result.php | 2 +- etc/adminhtml/system.xml | 45 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Helper/Checkout.php b/Helper/Checkout.php index 978202f5..bb0458af 100755 --- a/Helper/Checkout.php +++ b/Helper/Checkout.php @@ -195,7 +195,6 @@ private function getEstimatedAddress( public function getMethodPrice(string $carrier, string $key, bool $addBasePrice = true): float { $value = (float) $this->getCarrierConfig($key, $carrier); - file_put_contents('/Applications/MAMP/htdocs/MagentoNL/var/log/joeri.log', "$value $carrier $key\n",FILE_APPEND); $showTotalPrice = $this->getCarrierConfig('shipping_methods/delivery_options_prices', Data::XML_PATH_GENERAL) === PriceDeliveryOptionsView::TOTAL; if ($showTotalPrice && $addBasePrice) { // Calculate value diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php index d9602eab..5b827e0f 100644 --- a/Model/Quote/Checkout.php +++ b/Model/Quote/Checkout.php @@ -206,9 +206,8 @@ private function getDeliveryData(?string $packageType = null): array } } - $basePrice = $this->helper->getBasePrice(); $deliveryFee = $this->helper->getMethodPrice($carrierPath, 'delivery/delivery_fee', false); - $basePrice += $deliveryFee; + $basePrice = $this->helper->getBasePrice() + $deliveryFee; $mondayFee = $canHaveMonday ? $this->helper->getMethodPrice($carrierPath, 'delivery/monday_fee') : 0; $morningFee = $canHaveMorning ? $this->helper->getMethodPrice($carrierPath, 'morning/fee') : 0; $eveningFee = $canHaveEvening ? $this->helper->getMethodPrice($carrierPath, 'evening/fee') : 0; diff --git a/Model/Rate/Result.php b/Model/Rate/Result.php index 12562455..55ef11f3 100755 --- a/Model/Rate/Result.php +++ b/Model/Rate/Result.php @@ -353,7 +353,7 @@ private function createTitle($settingPath) private function getPrice($settingPath): float { $basePrice = $this->myParcelHelper->getBasePrice(); - $settingFee = 0; + $settingFee = (float) $this->myParcelHelper->getConfigValue("{$settingPath}delivery_fee"); // Explode settingPath like: myparcelnl_magento_postnl_settings/delivery/only_recipient/signature $settingPath = explode('/', $settingPath ?? ''); diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index afdca610..476e9c92 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -731,6 +731,15 @@ Magento\Config\Model\Config\Source\Yesno + + + validate-number + Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + This will be added to or subtracted from the regular shipping price + + 1 + + @@ -1012,6 +1021,15 @@ Magento\Config\Model\Config\Source\Yesno + + + validate-number + Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + This will be added to or subtracted from the regular shipping price + + 1 + + @@ -1178,6 +1196,15 @@ Magento\Config\Model\Config\Source\Yesno + + + validate-number + Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + This will be added to or subtracted from the regular shipping price + + 1 + + @@ -1351,6 +1378,15 @@ Magento\Config\Model\Config\Source\Yesno + + + validate-number + Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + This will be added to or subtracted from the regular shipping price + + 1 + + @@ -1518,6 +1554,15 @@ Magento\Config\Model\Config\Source\Yesno + + + validate-number + Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + This will be added to or subtracted from the regular shipping price + + 1 + + From d7c24cb87e0f583f959066edea93eced8f0003dc Mon Sep 17 00:00:00 2001 From: jochemgravendeel Date: Mon, 11 Nov 2024 13:43:08 +0100 Subject: [PATCH 03/10] feat: add delivery fee --- Model/Quote/Checkout.php | 5 +++-- Model/Rate/Result.php | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php index 5b827e0f..19001a9c 100644 --- a/Model/Quote/Checkout.php +++ b/Model/Quote/Checkout.php @@ -206,8 +206,8 @@ private function getDeliveryData(?string $packageType = null): array } } + $basePrice = $this->helper->getBasePrice(); $deliveryFee = $this->helper->getMethodPrice($carrierPath, 'delivery/delivery_fee', false); - $basePrice = $this->helper->getBasePrice() + $deliveryFee; $mondayFee = $canHaveMonday ? $this->helper->getMethodPrice($carrierPath, 'delivery/monday_fee') : 0; $morningFee = $canHaveMorning ? $this->helper->getMethodPrice($carrierPath, 'morning/fee') : 0; $eveningFee = $canHaveEvening ? $this->helper->getMethodPrice($carrierPath, 'evening/fee') : 0; @@ -247,7 +247,7 @@ private function getDeliveryData(?string $packageType = null): array 'priceSignature' => $signatureFee, 'priceReceiptCode' => $receiptCodeFee, 'priceOnlyRecipient' => $onlyRecipientFee, - 'priceStandardDelivery' => $showTotalPrice ? $basePrice : 0, + 'priceStandardDelivery' => $showTotalPrice ? ($basePrice + $deliveryFee) : $deliveryFee, 'priceDeliveryFee' => $deliveryFee, 'priceMondayDelivery' => $mondayFee, 'priceMorningDelivery' => $morningFee, @@ -457,4 +457,5 @@ private function isPickupAllowed(string $carrier): bool return ! $this->package->deliveryOptionsDisabled && $pickupEnabled && $showPickup; } + } diff --git a/Model/Rate/Result.php b/Model/Rate/Result.php index 55ef11f3..11053370 100755 --- a/Model/Rate/Result.php +++ b/Model/Rate/Result.php @@ -156,6 +156,7 @@ public static function getMethods(): array 'digital_stamp' => 'digital_stamp', 'same_day_delivery' => 'delivery/same_day_delivery', 'same_day_delivery_only_recipient' => 'delivery/only_recipient/same_day_delivery', + 'delivery_fee' => 'delivery/delivery_fee', ]; } @@ -410,6 +411,13 @@ private function getPrice($settingPath): float return min($settingFee, $basePrice); } + if ($settingPath[self::SECOND_PART] === 'delivery') { + $deliveryFee = (float) $this->myParcelHelper->getConfigValue( + sprintf("%s/default_options/delivery_fee", $settingPath[self::FIRST_PART]) + ); + return $basePrice + $deliveryFee; + } + return $basePrice + $settingFee; } From da36eca4f0da181298628e6c6aaf339a2a500ecd Mon Sep 17 00:00:00 2001 From: jochemgravendeel Date: Mon, 11 Nov 2024 13:58:23 +0100 Subject: [PATCH 04/10] feat: add delivery fee --- Model/Rate/Result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Rate/Result.php b/Model/Rate/Result.php index 11053370..b1ddb010 100755 --- a/Model/Rate/Result.php +++ b/Model/Rate/Result.php @@ -354,7 +354,7 @@ private function createTitle($settingPath) private function getPrice($settingPath): float { $basePrice = $this->myParcelHelper->getBasePrice(); - $settingFee = (float) $this->myParcelHelper->getConfigValue("{$settingPath}delivery_fee"); + $settingFee = 0; // Explode settingPath like: myparcelnl_magento_postnl_settings/delivery/only_recipient/signature $settingPath = explode('/', $settingPath ?? ''); From 050fd4b1d3d2f1f22d22366f88a3db19ce938df6 Mon Sep 17 00:00:00 2001 From: Joeri van Veen Date: Thu, 14 Nov 2024 13:54:38 +0100 Subject: [PATCH 05/10] fix: calculate delivery fee before options --- Model/Rate/Result.php | 45 ++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/Model/Rate/Result.php b/Model/Rate/Result.php index b1ddb010..138c736e 100755 --- a/Model/Rate/Result.php +++ b/Model/Rate/Result.php @@ -357,67 +357,64 @@ private function getPrice($settingPath): float $settingFee = 0; // Explode settingPath like: myparcelnl_magento_postnl_settings/delivery/only_recipient/signature - $settingPath = explode('/', $settingPath ?? ''); + $settingPathParts = explode('/', $settingPath ?? ''); // Check if the selected delivery options are delivery, only_recipient and signature // delivery/only_recipient/signature - if (isset($settingPath[self::THIRD_PART], $settingPath[self::FOURTH_PART]) && 'delivery' === $settingPath[self::SECOND_PART]) { + if (isset($settingPathParts[self::THIRD_PART], $settingPathParts[self::FOURTH_PART]) && 'delivery' === $settingPathParts[self::SECOND_PART]) { $settingFee += (float) $this->myParcelHelper->getConfigValue( sprintf( "%s/%s/%s_fee", - $settingPath[self::FIRST_PART], - $settingPath[self::SECOND_PART], - $settingPath[self::THIRD_PART] + $settingPathParts[self::FIRST_PART], + $settingPathParts[self::SECOND_PART], + $settingPathParts[self::THIRD_PART] ) ); $settingFee += (float) $this->myParcelHelper->getConfigValue( sprintf( "%s/%s/%sfee", - $settingPath[self::FIRST_PART], - $settingPath[self::SECOND_PART], - $settingPath[self::FOURTH_PART] + $settingPathParts[self::FIRST_PART], + $settingPathParts[self::SECOND_PART], + $settingPathParts[self::FOURTH_PART] ) ); } // Check if the selected delivery is morning or evening and select the fee - if (AbstractConsignment::DELIVERY_TYPE_MORNING_NAME === $settingPath[self::SECOND_PART] || AbstractConsignment::DELIVERY_TYPE_EVENING_NAME === $settingPath[self::SECOND_PART]) { + if (AbstractConsignment::DELIVERY_TYPE_MORNING_NAME === $settingPathParts[self::SECOND_PART] || AbstractConsignment::DELIVERY_TYPE_EVENING_NAME === $settingPathParts[self::SECOND_PART]) { $settingFee = (float) $this->myParcelHelper->getConfigValue( - sprintf("%s/%s/fee", $settingPath[self::FIRST_PART], $settingPath[self::SECOND_PART]) + sprintf("%s/%s/fee", $settingPathParts[self::FIRST_PART], $settingPathParts[self::SECOND_PART]) ); // change delivery type if there is a signature selected - if (isset($settingPath[self::FOURTH_PART])) { - $settingPath[self::SECOND_PART] = 'delivery'; + if (isset($settingPathParts[self::FOURTH_PART])) { + $settingPathParts[self::SECOND_PART] = 'delivery'; } // Unset only_recipient to select the correct price - unset($settingPath[self::THIRD_PART]); + unset($settingPathParts[self::THIRD_PART]); + } else { + $settingFee += (float) $this->myParcelHelper->getConfigValue( + sprintf("%s/delivery/delivery_fee", $settingPathParts[self::FIRST_PART]) + ); } - $settingFee += (float) $this->myParcelHelper->getConfigValue(implode('/', $settingPath ?? []) . 'fee'); + $settingFee += (float) $this->myParcelHelper->getConfigValue(implode('/', $settingPathParts ?? []) . 'fee'); // For mailbox and digital stamp the base price should not be calculated - if (AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME === $settingPath[self::SECOND_PART]) { + if (AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME === $settingPathParts[self::SECOND_PART]) { // for international mailbox, we have a different price :-) $cc = $this->session->getQuote()->getShippingAddress()->getCountryId(); if ($cc !== 'NL') { $settingFee = (float) $this->myParcelHelper->getConfigValue( - sprintf("%s/%s/international_fee", $settingPath[self::FIRST_PART], $settingPath[self::SECOND_PART]) + sprintf("%s/%s/international_fee", $settingPathParts[self::FIRST_PART], $settingPathParts[self::SECOND_PART]) ); } return min($settingFee, $basePrice); } - if (AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME === $settingPath[self::SECOND_PART]){ + if (AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME === $settingPathParts[self::SECOND_PART]){ return min($settingFee, $basePrice); } - if ($settingPath[self::SECOND_PART] === 'delivery') { - $deliveryFee = (float) $this->myParcelHelper->getConfigValue( - sprintf("%s/default_options/delivery_fee", $settingPath[self::FIRST_PART]) - ); - return $basePrice + $deliveryFee; - } - return $basePrice + $settingFee; } From 3ee3e9e7d68bd042dd08bfb066d82227609a73d4 Mon Sep 17 00:00:00 2001 From: Joeri van Veen Date: Thu, 14 Nov 2024 14:03:42 +0100 Subject: [PATCH 06/10] refactor: clearer part name constants --- Model/Rate/Result.php | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Model/Rate/Result.php b/Model/Rate/Result.php index 138c736e..f8ec225c 100755 --- a/Model/Rate/Result.php +++ b/Model/Rate/Result.php @@ -31,11 +31,11 @@ class Result extends \Magento\Shipping\Model\Rate\Result { - private const FIRST_PART = 0; - private const SECOND_PART = 1; - private const THIRD_PART = 2; - private const FOURTH_PART = 3; - private const CARRIERS_WITH_MAILBOX = [ + private const CARRIER_PATH = 0; + private const DELIVERY_PART = 1; + private const FIRST_SHIPPING_OPTION = 2; + private const SECOND_SHIPPING_OPTION = 3; + private const CARRIERS_WITH_MAILBOX = [ CarrierPostNL::NAME, CarrierDHLForYou::NAME, CarrierDPD::NAME, @@ -357,61 +357,61 @@ private function getPrice($settingPath): float $settingFee = 0; // Explode settingPath like: myparcelnl_magento_postnl_settings/delivery/only_recipient/signature - $settingPathParts = explode('/', $settingPath ?? ''); + $settingPathParts = explode('/', $settingPath ?? '');// + [null, null, null, null]; // Check if the selected delivery options are delivery, only_recipient and signature // delivery/only_recipient/signature - if (isset($settingPathParts[self::THIRD_PART], $settingPathParts[self::FOURTH_PART]) && 'delivery' === $settingPathParts[self::SECOND_PART]) { + if (isset($settingPathParts[self::FIRST_SHIPPING_OPTION], $settingPathParts[self::SECOND_SHIPPING_OPTION]) && 'delivery' === $settingPathParts[self::DELIVERY_PART]) { $settingFee += (float) $this->myParcelHelper->getConfigValue( sprintf( "%s/%s/%s_fee", - $settingPathParts[self::FIRST_PART], - $settingPathParts[self::SECOND_PART], - $settingPathParts[self::THIRD_PART] + $settingPathParts[self::CARRIER_PATH], + $settingPathParts[self::DELIVERY_PART], + $settingPathParts[self::FIRST_SHIPPING_OPTION] ) ); $settingFee += (float) $this->myParcelHelper->getConfigValue( sprintf( "%s/%s/%sfee", - $settingPathParts[self::FIRST_PART], - $settingPathParts[self::SECOND_PART], - $settingPathParts[self::FOURTH_PART] + $settingPathParts[self::CARRIER_PATH], + $settingPathParts[self::DELIVERY_PART], + $settingPathParts[self::SECOND_SHIPPING_OPTION] ) ); } // Check if the selected delivery is morning or evening and select the fee - if (AbstractConsignment::DELIVERY_TYPE_MORNING_NAME === $settingPathParts[self::SECOND_PART] || AbstractConsignment::DELIVERY_TYPE_EVENING_NAME === $settingPathParts[self::SECOND_PART]) { + if (AbstractConsignment::DELIVERY_TYPE_MORNING_NAME === $settingPathParts[self::DELIVERY_PART] || AbstractConsignment::DELIVERY_TYPE_EVENING_NAME === $settingPathParts[self::DELIVERY_PART]) { $settingFee = (float) $this->myParcelHelper->getConfigValue( - sprintf("%s/%s/fee", $settingPathParts[self::FIRST_PART], $settingPathParts[self::SECOND_PART]) + sprintf("%s/%s/fee", $settingPathParts[self::CARRIER_PATH], $settingPathParts[self::DELIVERY_PART]) ); // change delivery type if there is a signature selected - if (isset($settingPathParts[self::FOURTH_PART])) { - $settingPathParts[self::SECOND_PART] = 'delivery'; + if (isset($settingPathParts[self::SECOND_SHIPPING_OPTION])) { + $settingPathParts[self::DELIVERY_PART] = 'delivery'; } // Unset only_recipient to select the correct price - unset($settingPathParts[self::THIRD_PART]); + unset($settingPathParts[self::FIRST_SHIPPING_OPTION]); } else { $settingFee += (float) $this->myParcelHelper->getConfigValue( - sprintf("%s/delivery/delivery_fee", $settingPathParts[self::FIRST_PART]) + sprintf("%s/delivery/delivery_fee", $settingPathParts[self::CARRIER_PATH]) ); } $settingFee += (float) $this->myParcelHelper->getConfigValue(implode('/', $settingPathParts ?? []) . 'fee'); // For mailbox and digital stamp the base price should not be calculated - if (AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME === $settingPathParts[self::SECOND_PART]) { + if (AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME === $settingPathParts[self::DELIVERY_PART]) { // for international mailbox, we have a different price :-) $cc = $this->session->getQuote()->getShippingAddress()->getCountryId(); if ($cc !== 'NL') { $settingFee = (float) $this->myParcelHelper->getConfigValue( - sprintf("%s/%s/international_fee", $settingPathParts[self::FIRST_PART], $settingPathParts[self::SECOND_PART]) + sprintf("%s/%s/international_fee", $settingPathParts[self::CARRIER_PATH], $settingPathParts[self::DELIVERY_PART]) ); } return min($settingFee, $basePrice); } - if (AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME === $settingPathParts[self::SECOND_PART]){ + if (AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME === $settingPathParts[self::DELIVERY_PART]){ return min($settingFee, $basePrice); } From 5a0eb06d29a8117cdc80aa87ce4661867ac34bf6 Mon Sep 17 00:00:00 2001 From: jochemgravendeel Date: Thu, 21 Nov 2024 13:47:04 +0100 Subject: [PATCH 07/10] fix comments --- Model/Quote/Checkout.php | 2 +- i18n/fr_FR.csv | 1 + i18n/nl_NL.csv | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php index 19001a9c..266bac26 100644 --- a/Model/Quote/Checkout.php +++ b/Model/Quote/Checkout.php @@ -206,7 +206,7 @@ private function getDeliveryData(?string $packageType = null): array } } - $basePrice = $this->helper->getBasePrice(); + $basePrice = $this->helper->getBasePrice(); $deliveryFee = $this->helper->getMethodPrice($carrierPath, 'delivery/delivery_fee', false); $mondayFee = $canHaveMonday ? $this->helper->getMethodPrice($carrierPath, 'delivery/monday_fee') : 0; $morningFee = $canHaveMorning ? $this->helper->getMethodPrice($carrierPath, 'morning/fee') : 0; diff --git a/i18n/fr_FR.csv b/i18n/fr_FR.csv index 93284b04..c9859923 100644 --- a/i18n/fr_FR.csv +++ b/i18n/fr_FR.csv @@ -227,3 +227,4 @@ signature_title, Signature à réception receipt_code_title, Code de réception only_recipient_title, Adresse de résidence uniquement saturday_delivery, Livraison le samedi +delivery_fee, Frais de livraison diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index 81f85927..e3f56c90 100755 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -319,3 +319,4 @@ signature_title, Handtekening voor ontvangst only_recipient_title, Alleen huisadres receipt_code_title, Ontvangstcode saturday_delivery, Zaterdag levering +delivery_fee, Bezorgkosten From d9bdee65bf9363367c19732958b9ba0e1e325cb5 Mon Sep 17 00:00:00 2001 From: jochemgravendeel Date: Thu, 21 Nov 2024 16:08:00 +0100 Subject: [PATCH 08/10] fix comments --- Helper/Checkout.php | 3 +++ Model/Rate/Result.php | 2 +- i18n/fr_FR.csv | 2 +- i18n/nl_NL.csv | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Helper/Checkout.php b/Helper/Checkout.php index bb0458af..ca1610e2 100755 --- a/Helper/Checkout.php +++ b/Helper/Checkout.php @@ -196,10 +196,12 @@ public function getMethodPrice(string $carrier, string $key, bool $addBasePrice { $value = (float) $this->getCarrierConfig($key, $carrier); $showTotalPrice = $this->getCarrierConfig('shipping_methods/delivery_options_prices', Data::XML_PATH_GENERAL) === PriceDeliveryOptionsView::TOTAL; + if ($showTotalPrice && $addBasePrice) { // Calculate value $value = (float) $this->getBasePrice() + $value; } + return $value; } @@ -232,6 +234,7 @@ public function getCarrierConfig(string $code, string $carrier) $this->_logger->critical('Can\'t get setting with path:' . $carrier . $code); return 0; } + return $value; } diff --git a/Model/Rate/Result.php b/Model/Rate/Result.php index f8ec225c..0e3b1ed6 100755 --- a/Model/Rate/Result.php +++ b/Model/Rate/Result.php @@ -357,7 +357,7 @@ private function getPrice($settingPath): float $settingFee = 0; // Explode settingPath like: myparcelnl_magento_postnl_settings/delivery/only_recipient/signature - $settingPathParts = explode('/', $settingPath ?? '');// + [null, null, null, null]; + $settingPathParts = explode('/', $settingPath ?? ''); // Check if the selected delivery options are delivery, only_recipient and signature // delivery/only_recipient/signature diff --git a/i18n/fr_FR.csv b/i18n/fr_FR.csv index c9859923..e2d9b799 100644 --- a/i18n/fr_FR.csv +++ b/i18n/fr_FR.csv @@ -206,6 +206,7 @@ Saturday,Samedi Sunday,Dimanche Automate 'Large format',Automatiser "Plus grand que 100 x 70 x 58 cm ou plus lourd que 23 kg" Large package,Plus grand que 100 x 70 x 58 cm ou plus lourd que 23 kg +Delivery fee,Frais de livraison {field} is required.,{field} est requis. Address not found.,Adresse introuvable. @@ -227,4 +228,3 @@ signature_title, Signature à réception receipt_code_title, Code de réception only_recipient_title, Adresse de résidence uniquement saturday_delivery, Livraison le samedi -delivery_fee, Frais de livraison diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index e3f56c90..2ccd5151 100755 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -289,6 +289,7 @@ This is the type of weight that I use with my products.,Dit is de eenheid die je Default,Standaard No,Nee Yes,Ja +Delivery fee,Bezorgkosten {field} is required.,{field} is verplicht. Address not found.,Dit adres is niet gevonden. @@ -319,4 +320,3 @@ signature_title, Handtekening voor ontvangst only_recipient_title, Alleen huisadres receipt_code_title, Ontvangstcode saturday_delivery, Zaterdag levering -delivery_fee, Bezorgkosten From 99d0a655ccc1fe0ed7b42a959ea5ef9e54e3c565 Mon Sep 17 00:00:00 2001 From: jochemgravendeel Date: Fri, 22 Nov 2024 09:23:05 +0100 Subject: [PATCH 09/10] fix xml error --- etc/adminhtml/system.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 9b009c75..55d7903d 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1560,6 +1560,7 @@ validate-number Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. This will be added to or subtracted from the regular shipping price + From e2c94936b3cbf9b94872d838e0194547018286d9 Mon Sep 17 00:00:00 2001 From: Joeri van Veen Date: Fri, 22 Nov 2024 10:38:28 +0100 Subject: [PATCH 10/10] fix: prevent double settingfee calculation --- Model/Rate/Result.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Model/Rate/Result.php b/Model/Rate/Result.php index 0e3b1ed6..fb355a5c 100755 --- a/Model/Rate/Result.php +++ b/Model/Rate/Result.php @@ -392,10 +392,6 @@ private function getPrice($settingPath): float } // Unset only_recipient to select the correct price unset($settingPathParts[self::FIRST_SHIPPING_OPTION]); - } else { - $settingFee += (float) $this->myParcelHelper->getConfigValue( - sprintf("%s/delivery/delivery_fee", $settingPathParts[self::CARRIER_PATH]) - ); } $settingFee += (float) $this->myParcelHelper->getConfigValue(implode('/', $settingPathParts ?? []) . 'fee');