diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php
index 9b119460..3f24356b 100644
--- a/Model/Quote/Checkout.php
+++ b/Model/Quote/Checkout.php
@@ -65,6 +65,7 @@ public function __construct(
$this->package->setMailboxSettings();
$this->package->setDigitalStampSettings();
+ $this->package->setPackageSmallSettings();
}
/**
@@ -135,6 +136,9 @@ private function getPackageType(): string
return AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME;
case AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME:
$packageType = AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME;
+ break;
+ case AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL_NAME:
+ return AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL_NAME;
}
}
@@ -163,8 +167,9 @@ private function getDeliveryData(): array
continue;
}
- $canHaveDigitalStamp = $consignment->canHaveDeliveryType(AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME);
- $canHaveMailbox = $consignment->canHaveDeliveryType(AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME);
+ $canHaveDigitalStamp = $consignment->canHavePackageType(AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME);
+ $canHaveMailbox = $consignment->canHavePackageType(AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME);
+ $canHavePackageSmall = $consignment->canHavePackageType(AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL_NAME);
$canHaveSameDay = $consignment->canHaveExtraOption(AbstractConsignment::SHIPMENT_OPTION_SAME_DAY_DELIVERY);
$canHaveMonday = $consignment->canHaveExtraOption(AbstractConsignment::EXTRA_OPTION_DELIVERY_MONDAY);
$canHaveMorning = $consignment->canHaveDeliveryType(AbstractConsignment::DELIVERY_TYPE_MORNING_NAME);
@@ -213,6 +218,7 @@ private function getDeliveryData(): array
'pricePickup' => $canHavePickup ? $this->helper->getMethodPrice($carrierPath, 'pickup/fee') : 0,
'pricePackageTypeMailbox' => $canHaveMailbox ? $this->helper->getMethodPrice($carrierPath, 'mailbox/fee', false) : 0,
'pricePackageTypeDigitalStamp' => $canHaveDigitalStamp ? $this->helper->getMethodPrice($carrierPath, 'digital_stamp/fee', false) : 0,
+ 'pricePackageTypePackageSmall' => $canHavePackageSmall ? $this->helper->getMethodPrice($carrierPath, 'package_small/fee', false) : 0,
],
$canHaveSameDay ? [
'cutoffTimeSameDay' => $this->helper->getTimeConfig(
@@ -313,10 +319,12 @@ public function checkPackageType(string $carrier, ?string $country = null): stri
$country = $country ?? $this->cart->getShippingAddress()->getCountryId();
$canHaveDigitalStamp = $consignment->canHavePackageType(AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP_NAME);
$canHaveMailbox = $consignment->canHavePackageType(AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME);
+ $canHavePackageSmall = $consignment->canHavePackageType(AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL_NAME);
$this->package->setCurrentCountry($country);
$this->package->setDigitalStampActive($canHaveDigitalStamp && $this->helper->getBoolConfig($carrierPath, 'digital_stamp/active'));
$this->package->setMailboxActive($canHaveMailbox && $this->helper->getBoolConfig($carrierPath, 'mailbox/active'));
+ $this->package->setPackageSmallActive($canHavePackageSmall && $this->helper->getBoolConfig($carrierPath, 'package_small/active'));
return $this->package->selectPackageType($products, $carrierPath);
}
diff --git a/Model/Sales/Package.php b/Model/Sales/Package.php
index 8e4e22a3..32d0fa2a 100755
--- a/Model/Sales/Package.php
+++ b/Model/Sales/Package.php
@@ -42,11 +42,21 @@ class Package extends Data implements PackageInterface
*/
private $maxDigitalStampWeight = 0;
+ /**
+ * @var float
+ */
+ private $maxPackageSmallWeight = 0;
+
/**
* @var bool
*/
private $mailboxActive = false;
+ /**
+ * @var bool
+ */
+ private $packageSmallActive = false;
+
/**
* @var bool
*/
@@ -149,6 +159,24 @@ public function setMailboxActive(bool $mailboxActive): void
$this->mailboxActive = $mailboxActive;
}
+ /**
+ * @return bool
+ */
+ public function isPackageSmallActive(): bool
+ {
+ return $this->packageSmallActive;
+ }
+
+ /**
+ * @param bool $packageSmallActive
+ *
+ * @return void
+ */
+ public function setPackageSmallActive(bool $packageSmallActive): void
+ {
+ $this->packageSmallActive = $packageSmallActive;
+ }
+
/**
* @param bool $isActive
*
@@ -201,6 +229,20 @@ public function setDigitalStampActive(bool $digitalStampActive): void
$this->digitalStampActive = $digitalStampActive;
}
+ public function getMaxPackageSmallWeight(): float
+ {
+ return $this->maxPackageSmallWeight;
+ }
+
+ /**
+ * @param float $maxWeight
+ *
+ * @return void
+ */
+ protected function setMaxPackageSmallWeight(float $maxWeight): void
+ {
+ $this->maxPackageSmallWeight = $maxWeight;
+ }
/**
* @param bool $allProductsFit
diff --git a/Model/Sales/Repository/PackageRepository.php b/Model/Sales/Repository/PackageRepository.php
index cba17337..ede65840 100755
--- a/Model/Sales/Repository/PackageRepository.php
+++ b/Model/Sales/Repository/PackageRepository.php
@@ -25,6 +25,7 @@ class PackageRepository extends Package
{
public const DEFAULT_MAXIMUM_MAILBOX_WEIGHT = 2000;
public const MAXIMUM_DIGITAL_STAMP_WEIGHT = 2000;
+ public const MAXIMUM_PACKAGE_SMALL_WEIGHT = 2000;
public const DEFAULT_LARGE_FORMAT_WEIGHT = 23000;
/**
@@ -40,11 +41,6 @@ class PackageRepository extends Package
*/
public function selectPackageType(array $products, string $carrierPath): string
{
- // When age check is enabled, only packagetype 'package' is possible
- if ($this->getAgeCheck($products, $carrierPath)) {
- return AbstractConsignment::PACKAGE_TYPE_PACKAGE_NAME;
- }
-
$this->setMailboxPercentage(0);
$weight = 0;
$digitalStamp = true;
@@ -95,6 +91,10 @@ public function selectPackageType(array $products, string $carrierPath): string
return AbstractConsignment::PACKAGE_TYPE_MAILBOX_NAME;
}
+ if ($this->fitInPackageSmall()) {
+ return AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL_NAME;
+ }
+
return AbstractConsignment::PACKAGE_TYPE_PACKAGE_NAME;
}
@@ -241,6 +241,7 @@ public function getAgeCheck(array $products, string $carrierPath): bool
public function setDigitalStampSettings(string $carrierPath = self::XML_PATH_POSTNL_SETTINGS): PackageRepository
{
$settings = $this->getConfigValue("{$carrierPath}digital_stamp");
+
if (null === $settings || ! array_key_exists('active', $settings)) {
$this->_logger->critical("Can't set settings with path: {$carrierPath}digital_stamp");
@@ -248,6 +249,7 @@ public function setDigitalStampSettings(string $carrierPath = self::XML_PATH_POS
}
$this->setDigitalStampActive('1' === $settings['active']);
+
if ($this->isDigitalStampActive()) {
$this->setMaxDigitalStampWeight(self::MAXIMUM_DIGITAL_STAMP_WEIGHT);
}
@@ -255,6 +257,54 @@ public function setDigitalStampSettings(string $carrierPath = self::XML_PATH_POS
return $this;
}
+ /**
+ * Init all package small settings
+ *
+ * @param string $carrierPath
+ *
+ * @return $this
+ */
+ public function setPackageSmallSettings(string $carrierPath = self::XML_PATH_POSTNL_SETTINGS): PackageRepository
+ {
+ $settings = $this->getConfigValue("{$carrierPath}package_small");
+
+ if (null === $settings || ! array_key_exists('active', $settings)) {
+ $this->_logger->critical("Can't set settings with path: {$carrierPath}digital_stamp");
+
+ return $this;
+ }
+
+ $this->setPackageSmallActive('1' === $settings['active']);
+ if ($this->isPackageSmallActive()) {
+ $weight = abs((float) str_replace(',', '.', $settings['weight'] ?? ''));
+ $unit = $this->getGeneralConfig('print/weight_indication');
+
+ if ('kilo' === $unit) {
+ $epsilon = 0.00001;
+ $default = self::MAXIMUM_PACKAGE_SMALL_WEIGHT / 1000.0;
+ if ($weight < $epsilon) {
+ $weight = $default;
+ }
+ $this->setMaxPackageSmallWeight($weight);
+ } else {
+ $weight = (int)$weight;
+ $this->setMaxPackageSmallWeight($weight ?: self::MAXIMUM_PACKAGE_SMALL_WEIGHT);
+ }
+ }
+
+ return $this;
+ }
+
+ /**
+ * @return bool
+ */
+ private function fitInPackageSmall(): bool
+ {
+ return AbstractConsignment::CC_BE !== $this->getCurrentCountry()
+ && $this->isPackageSmallActive()
+ && $this->getWeight() <= $this->getMaxPackageSmallWeight();
+ }
+
/**
* @param \Magento\Quote\Model\Quote\Item $product
* @param string $column
diff --git a/Model/Sales/TrackTraceHolder.php b/Model/Sales/TrackTraceHolder.php
index 1c2e4a50..b2dd45ca 100755
--- a/Model/Sales/TrackTraceHolder.php
+++ b/Model/Sales/TrackTraceHolder.php
@@ -139,7 +139,6 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options)
$order = $shipment->getOrder();
$checkoutData = $order->getData('myparcel_delivery_options') ?? '';
$deliveryOptions = json_decode($checkoutData, true) ?? [];
- $deliveryOptions['packageType'] = $options['package_type'];
$deliveryOptions['carrier'] = $this->getCarrierFromOptions($options)
?? $deliveryOptions['carrier']
?? DefaultOptions::getDefaultCarrier()
@@ -199,6 +198,9 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options)
$this->dataHelper->setOrderStatus($magentoTrack->getOrderId(), Order::STATE_NEW);
}
+ if (isset($deliveryOptions['packageType'])) {
+ $options['package_type'] = $deliveryOptions['packageType'];
+ }
$packageType = $this->getPackageType($options, $magentoTrack, $address);
$dropOffPoint = $this->dataHelper->getDropOffPoint(
CarrierFactory::createFromName($deliveryOptionsAdapter->getCarrier())
@@ -501,26 +503,29 @@ private function getCarrierFromOptions(array $options): ?string
/**
* @param array $options
+ * @param string $packageType
* @param Order\Shipment\Track $magentoTrack
* @param object $address
*
* @return int
- * @throws LocalizedException
+ * @throws \Magento\Framework\Exception\LocalizedException
*/
private function getPackageType(array $options, Track $magentoTrack, $address): int
{
- // get packagetype from delivery_options and use it for process directly
- $packageType = self::$defaultOptions->getPackageType();
- // get packagetype from selected radio buttons and check if package type is set
- if ($options['package_type'] && 'default' !== $options['package_type']) {
- $packageType = $options['package_type'] ?? AbstractConsignment::PACKAGE_TYPE_PACKAGE;
+ if ($this->getAgeCheck($magentoTrack, $address, $options)) {
+ return AbstractConsignment::PACKAGE_TYPE_PACKAGE;
+ }
+
+ // get package type from selected radio buttons and check if package type is set
+ $packageType = $options['package_type'] ?? 'default';
+ if ('default' === $packageType) {
+ $packageType = self::$defaultOptions->getPackageType();
}
if (! is_numeric($packageType)) {
- $packageType = AbstractConsignment::PACKAGE_TYPES_NAMES_IDS_MAP[$packageType];
+ $packageType = AbstractConsignment::PACKAGE_TYPES_NAMES_IDS_MAP[$packageType] ?? self::$defaultOptions->getPackageType();
}
- return $this->getAgeCheck($magentoTrack, $address, $options) ? AbstractConsignment::PACKAGE_TYPE_PACKAGE
- : $packageType;
+ return $packageType;
}
}
diff --git a/composer.json b/composer.json
index 96d7feca..2d94a77c 100755
--- a/composer.json
+++ b/composer.json
@@ -30,7 +30,7 @@
"type": "magento2-module",
"require": {
"php": "~5.6.5 || ^7.0 || ^8.0",
- "myparcelnl/sdk": "~v7.10.0",
+ "myparcelnl/sdk": "~v7.11.0",
"magento/framework": ">=101.0.8 <102 || >=102.0.1"
},
"require-dev": {
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index 01721a3c..322f6bea 100755
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -428,6 +428,28 @@
+
+
+
+
+ Automatically select package type 'Small Package' for orders under 2000 grams. Package type will be 'Small Package' when a product has setting 'Fit in mailbox' set to 0 and the weight is under 2000 grams.
+ Magento\Config\Model\Config\Source\Yesno
+
+
+
+ Shipments heavier than the weight specified here will not be of package type 'Small Package'.
+
+ 1
+
+
+
+
+ Enter a basic price for a mailbox. The regular price will not affect this price.
+
+ 1
+
+
+
diff --git a/i18n/en_US.csv b/i18n/en_US.csv
index 1021b6da..afc84a64 100755
--- a/i18n/en_US.csv
+++ b/i18n/en_US.csv
@@ -52,4 +52,5 @@ myparcelnl_magento_error_no_shipments_to_process, No MyParcel shipments to proce
no_account_settings, No account settings found. Press the import button in general configuration to fetch account settings.
manage_drop_off_point, Manage your default drop-off point in the
location_page, location manager
+package_small, Small package
diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv
index 8d490729..c3ff0f51 100755
--- a/i18n/nl_NL.csv
+++ b/i18n/nl_NL.csv
@@ -55,6 +55,7 @@ myparcelnl_magento_dhlparcelconnect_settings/delivery, DHL Parcel Connect bezorg
myparcelnl_magento_ups_settings/delivery, UPS bezorging
myparcelnl_magento_dpd_settings/delivery, DPD bezorging
myparcelnl_magento_error_no_shipments_to_process, Geen MyParcel zendingen om te verwerken.
+package_small, Klein pakket
Version and support,Versie en support
General settings,Algemene instellingen
API settings,API instellingen
@@ -262,6 +263,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
+
no_account_settings, Geen accountsettings gevonden. Klik op de importeer knop in het algemene configuratie scherm.
manage_drop_off_point, Beheer jouw standaard afleverpunt in de
location_page, locatiewijzer
diff --git a/view/adminhtml/web/template/grid/order_massaction.html b/view/adminhtml/web/template/grid/order_massaction.html
index 11ec0c69..75a95fa7 100755
--- a/view/adminhtml/web/template/grid/order_massaction.html
+++ b/view/adminhtml/web/template/grid/order_massaction.html
@@ -95,6 +95,11 @@
name="mypa_package_type" value="3">
+
+
+
+
diff --git a/view/frontend/web/js/view/delivery-options.js b/view/frontend/web/js/view/delivery-options.js
index c8c4fac3..df219fa3 100644
--- a/view/frontend/web/js/view/delivery-options.js
+++ b/view/frontend/web/js/view/delivery-options.js
@@ -71,6 +71,7 @@ define(
methodCodeDeliveryOptionsConfigMap: {
'myparcelnl_magento_postnl_settings/delivery': 'config.carrierSettings.postnl.priceStandardDelivery',
'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',
'myparcelnl_magento_postnl_settings/morning': 'config.carrierSettings.postnl.priceMorningDelivery',
'myparcelnl_magento_postnl_settings/evening': 'config.carrierSettings.postnl.priceEveningDelivery',