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 insurance custom be #755

Merged
merged 11 commits into from
Mar 3, 2023
32 changes: 19 additions & 13 deletions Model/Source/DefaultOptions.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php
/**
* All functions to handle insurance
*
* If you want to add improvements, please create a fork in our GitHub:
* https://github.com/myparcelnl
*
* @author Reindert Vetter <info@myparcel.nl>
* @copyright 2010-2019 MyParcel
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US CC BY-NC-ND 3.0 NL
* @link https://github.com/myparcelnl/magento
* @copyright 2010-2019 MyParcel
* @since File available since Release v0.1.0
*/

Expand All @@ -27,17 +26,17 @@
class DefaultOptions
{
// Maximum characters length of company name.
private const COMPANY_NAME_MAX_LENGTH = 50;
private const INSURANCE_BELGIUM = 'insurance_belgium';
private const INSURANCE_BELGIUM_AMOUNT = 500;
private const INSURANCE_EU_AMOUNT_50 = 'insurance_eu_50';
private const INSURANCE_EU_AMOUNT_500 = 'insurance_eu_500';
private const INSURANCE_AMOUNT_100 = 'insurance_100';
private const INSURANCE_AMOUNT_250 = 'insurance_250';
private const INSURANCE_AMOUNT_500 = 'insurance_500';
private const INSURANCE_AMOUNT_CUSTOM = 'insurance_custom';

public const DEFAULT_OPTION_VALUE = 'default';
private const COMPANY_NAME_MAX_LENGTH = 50;
private const INSURANCE_BELGIUM = 'insurance_belgium';
private const INSURANCE_BELGIUM_AMOUNT = 500;
private const INSURANCE_EU_AMOUNT_50 = 'insurance_eu_50';
private const INSURANCE_EU_AMOUNT_500 = 'insurance_eu_500';
private const INSURANCE_BE_AMOUNT_CUSTOM = 'insurance_be_custom';
private const INSURANCE_AMOUNT_100 = 'insurance_100';
private const INSURANCE_AMOUNT_250 = 'insurance_250';
private const INSURANCE_AMOUNT_500 = 'insurance_500';
private const INSURANCE_AMOUNT_CUSTOM = 'insurance_custom';
public const DEFAULT_OPTION_VALUE = 'default';

/**
* @var Data
Expand Down Expand Up @@ -205,6 +204,12 @@ private function getDefaultEuInsurance(string $carrier): int
*/
private function getDefaultBeInsurance(string $carrier): int
{
if ($this->hasDefault(self::INSURANCE_BE_AMOUNT_CUSTOM, $carrier)) {
return self::$helper->getConfigValue(
Data::CARRIERS_XML_PATH_MAP[$carrier] . 'default_options/insurance_be_custom_amount'
);
}

return $this->hasDefault(self::INSURANCE_BELGIUM, $carrier) ? self::INSURANCE_BELGIUM_AMOUNT : 0;
}

Expand Down Expand Up @@ -233,6 +238,7 @@ private function getDefaultLocalInsurance(string $carrier): int

return 0;
}

/**
* Get default of digital stamp weight
*
Expand Down
20 changes: 20 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@
<label>Automate 'Insure shipments to Belgium'</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="insurance_be_custom_active" translate="label" type="select" sortOrder="264" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Insure BE custom active</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="insurance_be_custom_amount" translate="label comment" type="select" sortOrder="265" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Insured BE amount</label>
<source_model>MyParcelNL\Magento\Model\Source\PostNLInsurancePossibilities</source_model>
<tooltip>A custom be insurance price within a range of possibilities.</tooltip>
<depends>
<field id="insurance_be_custom_active">1</field>
</depends>
</field>
<field id="insurance_be_custom_from_price" translate="label comment" type="text" sortOrder="266" showInDefault="1" showInWebsite="1" showInStore="1">
<label>From price</label>
<validate>validate-number validate-zero-or-greater</validate>
<tooltip>'Insurance be custom' operates above a certain custom order total amount.</tooltip>
<depends>
<field id="insurance_be_custom_active">1</field>
</depends>
</field>
<field id="insurance_eu_50_active" translate="label" type="select" sortOrder="260" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Automate 'Insurance EU € 50'</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
3 changes: 3 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<insurance_custom_active>0</insurance_custom_active>
<insurance_custom_amount>1000</insurance_custom_amount>
<insurance_custom_from_price>1</insurance_custom_from_price>
<insurance_be_custom_active>0</insurance_be_custom_active>
<insurance_be_custom_amount>1000</insurance_be_custom_amount>
<insurance_be_custom_from_price>1</insurance_be_custom_from_price>
</default_options>
<general>
<deliverydays_window>14</deliverydays_window>
Expand Down