Skip to content

Commit

Permalink
feat: add package type package_small
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Ernst committed Feb 29, 2024
1 parent 63113cc commit 781a0ab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Model/Consignment/AbstractConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,36 @@ 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 = [
self::PACKAGE_TYPE_PACKAGE_NAME,
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 = [
self::PACKAGE_TYPE_PACKAGE_NAME => self::PACKAGE_TYPE_PACKAGE,
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;
Expand Down
1 change: 1 addition & 0 deletions src/Model/Consignment/PostNLConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down
7 changes: 7 additions & 0 deletions src/Rule/Consignment/MaximumWeightRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
14 changes: 12 additions & 2 deletions src/Services/ConsignmentEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down

0 comments on commit 781a0ab

Please sign in to comment.