Skip to content

Commit

Permalink
feat: change digital stamp weight range (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Ernst authored Jan 2, 2024
1 parent 2f66d6e commit 7413d70
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 50 deletions.
90 changes: 48 additions & 42 deletions includes/admin/settings/CarrierSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ private function createCarrierOptions(
private function createDefaultExportSettingsArray(string $option, AbstractCarrier $carrier): array
{
$settings = [];
$euInsuranceAmounts = [0 => __('no_insurance', 'woocommerce-myparcel')] + WCMP_Data::getInsuranceAmounts('FR', $carrier->getName());
$euInsuranceAmounts =
[0 => __('no_insurance', 'woocommerce-myparcel')] + WCMP_Data::getInsuranceAmounts(
'FR',
$carrier->getName()
);
$nlInsuranceAmounts = WCMP_Data::getInsuranceAmounts(AbstractConsignment::CC_NL, $carrier->getName());

switch ($option) {
Expand Down Expand Up @@ -332,40 +336,40 @@ private function createDeliveryOptionsSettingsArray(string $option): array
]
);
break;
// case AbstractConsignment::SHIPMENT_OPTION_SAME_DAY_DELIVERY:
// $settings[] = [
// 'name' => WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY,
// 'condition' => WCMYPA_Settings::SETTING_CARRIER_DELIVERY_ENABLED,
// 'help_text' => __('shipment_options_same_day_delivery_help_text', 'woocommerce-myparcel'),
// 'label' => __('shipment_options_same_day_delivery', 'woocommerce-myparcel'),
// 'type' => 'toggle',
// ];
// $settings[] = WCMP_Settings_Data::getFeeField(
// WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY_FEE,
// [
// WCMYPA_Settings::SETTING_CARRIER_DELIVERY_ENABLED,
// WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY,
// ]
// );
// $settings[] = [
// 'name' => WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY_CUTOFF_TIME,
// 'type' => 'time',
// 'class' => ['wcmp__child'],
// 'condition' => [
// WCMYPA_Settings::SETTING_CARRIER_DELIVERY_ENABLED,
// WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY,
// ],
// 'label' => __('setting_carrier_cut_off_time_title', 'woocommerce-myparcel'),
// 'help_text' => __(
// 'shipment_options_same_day_delivery_cutoff_time_help_text',
// 'woocommerce-myparcel'
// ),
// 'default' => '09:00',
// 'custom_attributes' => [
// 'min' => '00:00',
// 'max' => '10:00',
// ],
// ];
// case AbstractConsignment::SHIPMENT_OPTION_SAME_DAY_DELIVERY:
// $settings[] = [
// 'name' => WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY,
// 'condition' => WCMYPA_Settings::SETTING_CARRIER_DELIVERY_ENABLED,
// 'help_text' => __('shipment_options_same_day_delivery_help_text', 'woocommerce-myparcel'),
// 'label' => __('shipment_options_same_day_delivery', 'woocommerce-myparcel'),
// 'type' => 'toggle',
// ];
// $settings[] = WCMP_Settings_Data::getFeeField(
// WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY_FEE,
// [
// WCMYPA_Settings::SETTING_CARRIER_DELIVERY_ENABLED,
// WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY,
// ]
// );
// $settings[] = [
// 'name' => WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY_CUTOFF_TIME,
// 'type' => 'time',
// 'class' => ['wcmp__child'],
// 'condition' => [
// WCMYPA_Settings::SETTING_CARRIER_DELIVERY_ENABLED,
// WCMYPA_Settings::SETTING_CARRIER_SAME_DAY_DELIVERY,
// ],
// 'label' => __('setting_carrier_cut_off_time_title', 'woocommerce-myparcel'),
// 'help_text' => __(
// 'shipment_options_same_day_delivery_cutoff_time_help_text',
// 'woocommerce-myparcel'
// ),
// 'default' => '09:00',
// 'custom_attributes' => [
// 'min' => '00:00',
// 'max' => '10:00',
// ],
// ];
break;
}

Expand Down Expand Up @@ -535,13 +539,16 @@ private function getCarrierDeliveryOptionsSettings(

$settings = [
[
'name' => WCMYPA_Settings::SETTING_CARRIER_DELIVERY_ENABLED,
'label' => sprintf(
'name' => WCMYPA_Settings::SETTING_CARRIER_DELIVERY_ENABLED,
'label' => sprintf(
__('setting_carrier_delivery_enabled', 'woocommerce-myparcel'),
$carrier->getHuman()
),
'help_text' => CarrierDHLForYou::NAME === $carrier->getName() ? __('carrier_dhl_for_you_today_help_text', 'woocommerce-myparcel') : '',
'type' => 'toggle',
'help_text' => CarrierDHLForYou::NAME === $carrier->getName() ? __(
'carrier_dhl_for_you_today_help_text',
'woocommerce-myparcel'
) : '',
'type' => 'toggle',
],
WCMP_Settings_Data::getFeeField(
WCMYPA_Settings::SETTING_CARRIER_DELIVERY_STANDARD_FEE,
Expand Down Expand Up @@ -587,9 +594,8 @@ private function getCarrierDeliveryOptionsSettings(
null => __('no_default_weight', 'woocommerce-myparcel'),
WCMP_Data::DIGITAL_STAMP_RANGES[0]['average'] => '0 - 20 gram',
WCMP_Data::DIGITAL_STAMP_RANGES[1]['average'] => '20 - 50 gram',
WCMP_Data::DIGITAL_STAMP_RANGES[2]['average'] => '50 - 100 gram',
WCMP_Data::DIGITAL_STAMP_RANGES[3]['average'] => '100 - 350 gram',
WCMP_Data::DIGITAL_STAMP_RANGES[4]['average'] => '350 - 2000 gram',
WCMP_Data::DIGITAL_STAMP_RANGES[2]['average'] => '50 - 350 gram',
WCMP_Data::DIGITAL_STAMP_RANGES[3]['average'] => '350 - 2000 gram',
],
'help_text' => __('setting_carrier_digital_stamp_help_text', 'woocommerce-myparcel'),
];
Expand Down
7 changes: 1 addition & 6 deletions includes/class-wcmp-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ class WCMP_Data
],
[
'min' => 50,
'max' => 100,
'average' => 75
],
[
'min' => 100,
'max' => 350,
'average' => 225
'average' => 200,
],
[
'min' => 350,
Expand Down
111 changes: 111 additions & 0 deletions migration/wcmp-upgrade-migration-v4-22-0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

declare(strict_types=1);

use migration\WCMP_Upgrade_Migration;
use MyParcelNL\Sdk\src\Model\Carrier\CarrierPostNL;

if (! defined('ABSPATH')) {
exit;
}

if (class_exists('WCMP_Upgrade_Migration_v4_22_0')) {
return new WCMP_Upgrade_Migration_v4_22_0();
}

/**
* Migrates pre v4.22.0 settings
* - move digital stamp weight ranges 50-100g adn 100-350g to 50-350g
*/
class WCMP_Upgrade_Migration_v4_22_0 extends WCMP_Upgrade_Migration
{
/**
* @var array
*/
private $newCheckoutSettings = [];

/**
* @var array
*/
private $newDhlEuroplusSettings;

/**
* @var array
*/
private $newDhlForYouSettings;

/**
* @var array
*/
private $newDhlParcelConnectSettings;

/**
* @var array
*/
private $newGeneralSettings = [];

/**
* @var array
*/
private $newPostNlSettings = [];

public function __construct()
{
parent::__construct();
}

/**
* @return void
*/
protected function import(): void
{
require_once(WCMYPA()->plugin_path() . '/vendor/autoload.php');
require_once(WCMYPA()->plugin_path() . '/includes/admin/settings/class-wcmypa-settings.php');
require_once(WCMYPA()->plugin_path() . '/includes/class-wcmp-data.php');
}

/**
* @return void
*/
protected function migrate(): void
{
$this->newGeneralSettings = $this->getSettings('woocommerce_myparcel_general_settings');
$this->newCheckoutSettings = $this->getSettings('woocommerce_myparcel_checkout_settings');
$this->newPostNlSettings = $this->getSettings('woocommerce_myparcel_postnl_settings');
$this->newDhlForYouSettings = $this->getSettings('woocommerce_myparcel_dhlforyou_settings');
$this->newDhlParcelConnectSettings = $this->getSettings('woocommerce_myparcel_dhlparcelconnect_settings');
$this->newDhlEuroplusSettings = $this->getSettings('woocommerce_myparcel_dhleuroplus_settings');

$this->migrateCarrierSettings();
}

/**
* @return void
*/
protected function migrateCarrierSettings(): void
{
$keyDpzDefaultWeight =
sprintf('%s_%s', CarrierPostNL::NAME, WCMYPA_Settings::SETTING_CARRIER_DIGITAL_STAMP_DEFAULT_WEIGHT);

if (in_array($this->newPostNlSettings[$keyDpzDefaultWeight], [75, 225], true)) {
$this->newPostNlSettings[$keyDpzDefaultWeight] = 200;
}
}

/**
* @return void
*/
protected function setOptionSettingsMap(): void
{
$this->optionSettingsMap = [
'woocommerce_myparcel_general_settings' => $this->newGeneralSettings,
'woocommerce_myparcel_checkout_settings' => $this->newCheckoutSettings,
'woocommerce_myparcel_postnl_settings' => $this->newPostNlSettings,
'woocommerce_myparcel_dhlforyou_settings' => $this->newDhlForYouSettings,
'woocommerce_myparcel_dhleuroplus_settings' => $this->newDhlEuroplusSettings,
'woocommecre_myparcel_dhlparcelconnect_settings' => $this->newDhlParcelConnectSettings,
];
}
}

return new WCMP_Upgrade_Migration_v4_22_0();
8 changes: 6 additions & 2 deletions woocommerce-myparcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Description: Export your WooCommerce orders to MyParcel (https://myparcel.nl/) and print labels directly from the WooCommerce admin
Author: MyParcel
Author URI: https://myparcel.nl
Version: 4.21.1-rc.2
Version: 4.22.0
Text Domain: woocommerce-myparcel
License: GPLv3 or later
Expand Down Expand Up @@ -296,7 +296,7 @@ public function do_install(): void
$installed_version = get_option($version_setting) ?: '0';

// installed version lower than plugin version?
if (version_compare($installed_version, $this->version, '<')) {
if (true) {
if (! $installed_version) {
$this->install();
} else {
Expand Down Expand Up @@ -356,6 +356,10 @@ protected function upgrade($installed_version): void
require_once('migration/wcmp-upgrade-migration-v4-4-1.php');
}

if (version_compare($installed_version, '4.22.0', '<')) {
require_once('migration/wcmp-upgrade-migration-v4-22-0.php');
}

require_once('migration/wcmp-upgrade-migration-always.php');
}
}
Expand Down

0 comments on commit 7413d70

Please sign in to comment.