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

feat: add delivery fee #872

Merged
merged 11 commits into from
Nov 25, 2024
3 changes: 0 additions & 3 deletions Helper/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,10 @@ 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;
}

Expand Down Expand Up @@ -234,7 +232,6 @@ public function getCarrierConfig(string $code, string $carrier)
$this->_logger->critical('Can\'t get setting with path:' . $carrier . $code);
return 0;
}

return $value;
}

Expand Down
7 changes: 5 additions & 2 deletions Model/Quote/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ private function getDeliveryData(?string $packageType = null): array
}
}

$basePrice = $this->helper->getBasePrice();
$basePrice = $this->helper->getBasePrice();
GravendeelJochem marked this conversation as resolved.
Show resolved Hide resolved
$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;
Expand Down Expand Up @@ -246,7 +247,8 @@ 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,
'priceEveningDelivery' => $eveningFee,
Expand Down Expand Up @@ -455,4 +457,5 @@ private function isPickupAllowed(string $carrier): bool

return ! $this->package->deliveryOptionsDisabled && $pickupEnabled && $showPickup;
}

}
8 changes: 8 additions & 0 deletions Model/Rate/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}

Expand Down Expand Up @@ -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;
}

Expand Down
54 changes: 54 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@
<label>Delivery enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="delivery_fee" translate="label comment" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Delivery fee</label>
GravendeelJochem marked this conversation as resolved.
Show resolved Hide resolved
<validate>validate-number</validate>
<comment>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.</comment>
<tooltip>This will be added to or subtracted from the regular shipping price</tooltip>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="monday_active" translate="label comment" type="select" sortOrder="306" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Monday delivery</label>
Expand Down Expand Up @@ -722,6 +731,15 @@
<label>Delivery enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="delivery_fee" translate="label comment" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Delivery fee</label>
<validate>validate-number</validate>
<comment>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.</comment>
<tooltip>This will be added to or subtracted from the regular shipping price</tooltip>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="signature_active" translate="label comment" type="select" sortOrder="310" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Signature on receipt</label>
Expand Down Expand Up @@ -1003,6 +1021,15 @@
<label>Delivery enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="delivery_fee" translate="label comment" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Delivery fee</label>
<validate>validate-number</validate>
<comment>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.</comment>
<tooltip>This will be added to or subtracted from the regular shipping price</tooltip>
<depends>
<field id="active">1</field>
</depends>
</field>
</group>
<group id="drop_off_days" translate="label comment" type="text" sortOrder="250" showInDefault="1"
showInWebsite="1" showInStore="1">
Expand Down Expand Up @@ -1169,6 +1196,15 @@
<label>Delivery enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="delivery_fee" translate="label comment" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Delivery fee</label>
<validate>validate-number</validate>
<comment>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.</comment>
<tooltip>This will be added to or subtracted from the regular shipping price</tooltip>
<depends>
<field id="active">1</field>
</depends>
</field>
</group>
<group id="drop_off_days" translate="label comment" type="text" sortOrder="250" showInDefault="1"
showInWebsite="1" showInStore="1">
Expand Down Expand Up @@ -1342,6 +1378,15 @@
<label>Delivery enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="delivery_fee" translate="label comment" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Delivery fee</label>
<validate>validate-number</validate>
<comment>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.</comment>
<tooltip>This will be added to or subtracted from the regular shipping price</tooltip>
<depends>
<field id="active">1</field>
</depends>
</field>
</group>
<group id="drop_off_days" translate="label comment" type="text" sortOrder="250" showInDefault="1"
showInWebsite="1" showInStore="1">
Expand Down Expand Up @@ -1509,6 +1554,15 @@
<label>Delivery enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="delivery_fee" translate="label comment" type="text" sortOrder="305" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Delivery fee</label>
<validate>validate-number</validate>
<comment>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.</comment>
<tooltip>This will be added to or subtracted from the regular shipping price</tooltip>
<depends>
<field id="active">1</field>
</depends>
</field>
</group>
<group id="drop_off_days" translate="label comment" type="text" sortOrder="250" showInDefault="1"
showInWebsite="1" showInStore="1">
Expand Down
6 changes: 6 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<large_format_active>No</large_format_active>
<large_format_from_price>1</large_format_from_price>
<age_check_active>0</age_check_active>
<delivery_fee>0</delivery_fee>
</default_options>
<general>
<deliverydays_window>14</deliverydays_window>
Expand Down Expand Up @@ -119,6 +120,7 @@
<insurance_local_amount>0</insurance_local_amount>
<insurance_belgium_amount>0</insurance_belgium_amount>
<insurance_percentage>0</insurance_percentage>
<delivery_fee>0</delivery_fee>
</default_options>
<general>
<deliverydays_window>14</deliverydays_window>
Expand Down Expand Up @@ -156,6 +158,7 @@
<insurance_eu_amount>0</insurance_eu_amount>
<insurance_row_amount>0</insurance_row_amount>
<insurance_percentage>0</insurance_percentage>
<delivery_fee>0</delivery_fee>
</default_options>
<general>
<deliverydays_window>14</deliverydays_window>
Expand All @@ -176,6 +179,7 @@
<insurance_eu_amount>0</insurance_eu_amount>
<insurance_row_amount>0</insurance_row_amount>
<insurance_percentage>0</insurance_percentage>
<delivery_fee>0</delivery_fee>
</default_options>
<general>
<deliverydays_window>14</deliverydays_window>
Expand All @@ -196,6 +200,7 @@

<myparcelnl_magento_ups_settings>
<default_options>
<delivery_fee>0</delivery_fee>
</default_options>
<general>
<deliverydays_window>3</deliverydays_window>
Expand All @@ -212,6 +217,7 @@

<myparcelnl_magento_dpd_settings>
<default_options>
<delivery_fee>0</delivery_fee>
</default_options>
<general>
<deliverydays_window>3</deliverydays_window>
Expand Down
1 change: 1 addition & 0 deletions view/frontend/web/js/view/delivery-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down