diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php index 4933ec9a..8c469b1e 100644 --- a/Model/Quote/Checkout.php +++ b/Model/Quote/Checkout.php @@ -209,6 +209,7 @@ private function getDeliveryData(?string $packageType = null): array } $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; $eveningFee = $canHaveEvening ? $this->helper->getMethodPrice($carrierPath, 'evening/fee') : 0; @@ -253,7 +254,8 @@ private function getDeliveryData(?string $packageType = null): array 'priceCollect' => $collectFee, 'priceReceiptCode' => $receiptCodeFee, 'priceOnlyRecipient' => $onlyRecipientFee, - 'priceStandardDelivery' => $showTotalPrice ? $basePrice : 0, + 'priceStandardDelivery' => $showTotalPrice ? ($basePrice + $deliveryFee) : $deliveryFee, + 'priceDeliveryFee' => $deliveryFee, 'priceMondayDelivery' => $mondayFee, 'priceMorningDelivery' => $morningFee, 'priceEveningDelivery' => $eveningFee, @@ -463,4 +465,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 12562455..fb355a5c 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, @@ -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', ]; } @@ -356,57 +357,57 @@ 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::FIRST_SHIPPING_OPTION], $settingPathParts[self::SECOND_SHIPPING_OPTION]) && 'delivery' === $settingPathParts[self::DELIVERY_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::CARRIER_PATH], + $settingPathParts[self::DELIVERY_PART], + $settingPathParts[self::FIRST_SHIPPING_OPTION] ) ); $settingFee += (float) $this->myParcelHelper->getConfigValue( sprintf( "%s/%s/%sfee", - $settingPath[self::FIRST_PART], - $settingPath[self::SECOND_PART], - $settingPath[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 === $settingPath[self::SECOND_PART] || AbstractConsignment::DELIVERY_TYPE_EVENING_NAME === $settingPath[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", $settingPath[self::FIRST_PART], $settingPath[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($settingPath[self::FOURTH_PART])) { - $settingPath[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($settingPath[self::THIRD_PART]); + unset($settingPathParts[self::FIRST_SHIPPING_OPTION]); } - $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::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", $settingPath[self::FIRST_PART], $settingPath[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 === $settingPath[self::SECOND_PART]){ + if (AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME === $settingPathParts[self::DELIVERY_PART]){ return min($settingFee, $basePrice); } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 69f8e756..55d7903d 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 + + @@ -722,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 + + @@ -1003,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 + + @@ -1169,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 + + @@ -1342,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 + + @@ -1509,14 +1554,24 @@ 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 + + Magento\Config\Model\Config\Source\Yesno + 1 + @@ -1561,6 +1616,7 @@ 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/i18n/fr_FR.csv b/i18n/fr_FR.csv index 1e73a64b..a3080b5b 100644 --- a/i18n/fr_FR.csv +++ b/i18n/fr_FR.csv @@ -213,6 +213,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. diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index 03e432ab..6112ef9f 100755 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -296,6 +296,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. 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',