From 9e1f81f8c02513f1b9b23eb4c62a80af179e04f9 Mon Sep 17 00:00:00 2001 From: markernst97 Date: Mon, 19 Feb 2024 16:37:50 +0100 Subject: [PATCH] feat: add package type package_small --- src/Model/Consignment/AbstractConsignment.php | 5 +++++ src/Model/Consignment/PostNLConsignment.php | 1 + src/Rule/Consignment/MaximumWeightRule.php | 7 +++++++ src/Services/ConsignmentEncode.php | 14 ++++++++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Model/Consignment/AbstractConsignment.php b/src/Model/Consignment/AbstractConsignment.php index 0599f887..de3d8c27 100755 --- a/src/Model/Consignment/AbstractConsignment.php +++ b/src/Model/Consignment/AbstractConsignment.php @@ -126,17 +126,20 @@ abstract class AbstractConsignment public const PACKAGE_TYPE_MAILBOX = 2; public const PACKAGE_TYPE_LETTER = 3; public const PACKAGE_TYPE_DIGITAL_STAMP = 4; + public const PACKAGE_TYPE_PACKAGE_SMALL = 6; public const PACKAGE_TYPE_PACKAGE_NAME = 'package'; public const PACKAGE_TYPE_MAILBOX_NAME = 'mailbox'; public const PACKAGE_TYPE_LETTER_NAME = 'letter'; public const PACKAGE_TYPE_DIGITAL_STAMP_NAME = 'digital_stamp'; + public const PACKAGE_TYPE_PACKAGE_SMALL_NAME = 'package_small'; public const PACKAGE_TYPES_IDS = [ self::PACKAGE_TYPE_PACKAGE, self::PACKAGE_TYPE_MAILBOX, self::PACKAGE_TYPE_LETTER, self::PACKAGE_TYPE_DIGITAL_STAMP, + self::PACKAGE_TYPE_PACKAGE_SMALL, ]; public const PACKAGE_TYPES_NAMES = [ @@ -144,6 +147,7 @@ abstract class AbstractConsignment self::PACKAGE_TYPE_MAILBOX_NAME, self::PACKAGE_TYPE_LETTER_NAME, self::PACKAGE_TYPE_DIGITAL_STAMP_NAME, + self::PACKAGE_TYPE_PACKAGE_SMALL_NAME, ]; public const PACKAGE_TYPES_NAMES_IDS_MAP = [ @@ -151,6 +155,7 @@ abstract class AbstractConsignment self::PACKAGE_TYPE_MAILBOX_NAME => self::PACKAGE_TYPE_MAILBOX, self::PACKAGE_TYPE_LETTER_NAME => self::PACKAGE_TYPE_LETTER, self::PACKAGE_TYPE_DIGITAL_STAMP_NAME => self::PACKAGE_TYPE_DIGITAL_STAMP, + self::PACKAGE_TYPE_PACKAGE_SMALL_NAME => self::PACKAGE_TYPE_PACKAGE_SMALL, ]; public const DEFAULT_PACKAGE_TYPE = self::PACKAGE_TYPE_PACKAGE; diff --git a/src/Model/Consignment/PostNLConsignment.php b/src/Model/Consignment/PostNLConsignment.php index 56051890..dcc3d73d 100644 --- a/src/Model/Consignment/PostNLConsignment.php +++ b/src/Model/Consignment/PostNLConsignment.php @@ -77,6 +77,7 @@ public function getAllowedPackageTypes(): array self::PACKAGE_TYPE_MAILBOX_NAME, self::PACKAGE_TYPE_LETTER_NAME, self::PACKAGE_TYPE_DIGITAL_STAMP_NAME, + self::PACKAGE_TYPE_PACKAGE_SMALL_NAME, ]; } diff --git a/src/Rule/Consignment/MaximumWeightRule.php b/src/Rule/Consignment/MaximumWeightRule.php index c7967fa8..5d0bac45 100644 --- a/src/Rule/Consignment/MaximumWeightRule.php +++ b/src/Rule/Consignment/MaximumWeightRule.php @@ -26,6 +26,10 @@ class MaximumWeightRule extends Rule * @var int */ public const MAX_COLLO_WEIGHT_DIGITAL_STAMP_GRAMS = 2000; + /** + * @var int + */ + public const MAX_COLLO_WEIGHT_PACKAGE_SMALL_GRAMS = 2000; /** * @param \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment $validationSubject @@ -50,6 +54,9 @@ public function validate($validationSubject): void case AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP: $weightLimit = self::MAX_COLLO_WEIGHT_DIGITAL_STAMP_GRAMS; break; + case AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL: + $weightLimit = self::MAX_COLLO_WEIGHT_PACKAGE_SMALL_GRAMS; + break; default: $weightLimit = null; } diff --git a/src/Services/ConsignmentEncode.php b/src/Services/ConsignmentEncode.php index c5c33ef7..c0b0f46a 100644 --- a/src/Services/ConsignmentEncode.php +++ b/src/Services/ConsignmentEncode.php @@ -334,8 +334,18 @@ private function validateCdConsignment(AbstractConsignment $consignment): void throw new MissingFieldException('Product data must be set for international MyParcel shipments. Use addItem().'); } - if ($consignment->getPackageType() !== AbstractConsignment::PACKAGE_TYPE_PACKAGE && $consignment->getPackageType() !== AbstractConsignment::PACKAGE_TYPE_LETTER) { - throw new MissingFieldException('For international shipments, package_type must be 1 (normal package) or 3 (letter).'); + if (in_array( + $consignment->getPackageType(), + [ + AbstractConsignment::PACKAGE_TYPE_PACKAGE, + AbstractConsignment::PACKAGE_TYPE_LETTER, + AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL, + ], + true + )) { + throw new MissingFieldException( + 'For international shipments, package_type must be 1 (normal package), 3 (letter) or 6 (small package).' + ); } if (empty($consignment->getInvoice())) {