From 93a25e30bb628208394965cd1756f7698d6b5369 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Mon, 31 Dec 2018 11:01:51 +0100 Subject: [PATCH 001/113] POSTNLM2-618 - Priority products for EPS and Globalpack --- Config/Provider/PepsConfiguration.php | 58 +++++++++++++++++++ Config/Provider/ProductOptions.php | 33 +++++++---- Config/Provider/ShippingOptions.php | 9 +++ Config/Source/Options/DefaultOptions.php | 23 +++++++- Config/Source/OptionsAbstract.php | 47 ++++++++++++++- Service/Handler/BarcodeHandler.php | 32 ++++++++-- Service/Order/ProductCodeAndType.php | 5 +- Service/Shipment/Barcode/Range.php | 39 ++++++++++++- Webservices/Endpoints/Barcode.php | 15 ++++- Webservices/Endpoints/Labelling.php | 2 +- .../Endpoints/LabellingWithoutConfirm.php | 2 +- etc/adminhtml/system/globalpack.xml | 9 ++- etc/adminhtml/system/postnlsettings.xml | 1 + etc/adminhtml/system/postnlsettings/peps.xml | 57 ++++++++++++++++++ etc/config.xml | 6 ++ 15 files changed, 307 insertions(+), 31 deletions(-) create mode 100644 Config/Provider/PepsConfiguration.php create mode 100644 etc/adminhtml/system/postnlsettings/peps.xml diff --git a/Config/Provider/PepsConfiguration.php b/Config/Provider/PepsConfiguration.php new file mode 100644 index 000000000..7993709f2 --- /dev/null +++ b/Config/Provider/PepsConfiguration.php @@ -0,0 +1,58 @@ +getConfigFromXpath(static::XPATH_BARCODE_TYPE, $storeId); + } + + /** + * @param null $storeId + * + * @return mixed + */ + public function getBarcodeRange($storeId = null) + { + return $this->getConfigFromXpath(static::XPATH_BARCODE_RANGE, $storeId); + } +} diff --git a/Config/Provider/ProductOptions.php b/Config/Provider/ProductOptions.php index addd251fd..f2bdd201b 100644 --- a/Config/Provider/ProductOptions.php +++ b/Config/Provider/ProductOptions.php @@ -56,6 +56,7 @@ class ProductOptions extends AbstractConfigProvider const XPATH_DEFAULT_PACKAGE_DELIVERY_TYPE = 'tig_postnl/delivery_settings/default_package_type'; const XPATH_ALTERNATIVE_DEFAULT_PACKAGE_DELIVERY_TYPE = 'tig_postnl/delivery_settings/alternative_package_type'; const XPATH_DEFAULT_EPS_PRODUCT_OPTION = 'tig_postnl/delivery_settings/default_eps_option'; + const XPATH_DEFAULT_GP_PRODUCT_OPTION = 'tig_postnl/globalpack/default_gp_option'; /** * Since 1.5.1 all product options are automaticly supported. @@ -71,7 +72,7 @@ public function getSupportedProductOptions() */ public function getDefaultProductOption() { - return $this->getConfigFromXpath(self::XPATH_DEFAULT_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_PRODUCT_OPTION); } /** @@ -79,7 +80,7 @@ public function getDefaultProductOption() */ public function getUseAlternativeDefault() { - return $this->getConfigFromXpath(self::XPATH_USE_ALTERNATIVE_DEFAULT_OPTION); + return $this->getConfigFromXpath(static::XPATH_USE_ALTERNATIVE_DEFAULT_OPTION); } /** @@ -91,7 +92,7 @@ public function getAlternativeDefaultMinAmount() return '0'; } - return $this->getConfigFromXpath(self::XPATH_ALTERNATIVE_DEFAULT_MIN_AMOUNT); + return $this->getConfigFromXpath(static::XPATH_ALTERNATIVE_DEFAULT_MIN_AMOUNT); } /** @@ -103,7 +104,7 @@ public function getAlternativeDefaultProductOption() return false; } - return $this->getConfigFromXpath(self::XPATH_ALTERNATIVE_DEFAULT_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_ALTERNATIVE_DEFAULT_PRODUCT_OPTION); } /** @@ -117,7 +118,7 @@ public function getDefaultEveningProductOption($country = null) return $this->getDefaultEveningBeProductOption(); } - return $this->getConfigFromXpath(self::XPATH_DEFAULT_EVENING_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_EVENING_PRODUCT_OPTION); } /** @@ -125,7 +126,7 @@ public function getDefaultEveningProductOption($country = null) */ public function getDefaultExtraAtHomeProductOption() { - return $this->getConfigFromXpath(self::XPATH_DEFAULT_EXTRAATHOME_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_EXTRAATHOME_PRODUCT_OPTION); } /** @@ -133,7 +134,7 @@ public function getDefaultExtraAtHomeProductOption() */ public function getDefaultEveningBeProductOption() { - return $this->getConfigFromXpath(self::XPATH_DEFAULT_EVENING_BE_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_EVENING_BE_PRODUCT_OPTION); } /** @@ -141,7 +142,7 @@ public function getDefaultEveningBeProductOption() */ public function getDefaultBeProductOption() { - return $this->getConfigFromXpath(self::XPATH_DEFAULT_BE_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_BE_PRODUCT_OPTION); } /** @@ -149,7 +150,15 @@ public function getDefaultBeProductOption() */ public function getDefaultEpsProductOption() { - return $this->getConfigFromXpath(self::XPATH_DEFAULT_EPS_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_EPS_PRODUCT_OPTION); + } + + /** + * @return mixed + */ + public function getDefaultGlobalpackOption() + { + return $this->getConfigFromXpath(static::XPATH_DEFAULT_GP_PRODUCT_OPTION); } /** @@ -157,7 +166,7 @@ public function getDefaultEpsProductOption() */ public function getDefaultPakjeGemakProductOption() { - return $this->getConfigFromXpath(self::XPATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_PAKJEGEMAK_PRODUCT_OPTION); } /** @@ -165,7 +174,7 @@ public function getDefaultPakjeGemakProductOption() */ public function getDefaultPakjeGemakEarlyProductOption() { - return $this->getConfigFromXpath(self::XPATH_DEFAULT_PAKJEGEMAK_EARLY_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_PAKJEGEMAK_EARLY_PRODUCT_OPTION); } /** @@ -173,7 +182,7 @@ public function getDefaultPakjeGemakEarlyProductOption() */ public function getDefaultSundayProductOption() { - return $this->getConfigFromXpath(self::XPATH_DEFAULT_SUNDAY_PRODUCT_OPTION); + return $this->getConfigFromXpath(static::XPATH_DEFAULT_SUNDAY_PRODUCT_OPTION); } /** diff --git a/Config/Provider/ShippingOptions.php b/Config/Provider/ShippingOptions.php index a4ad16ad8..460f2e0fa 100644 --- a/Config/Provider/ShippingOptions.php +++ b/Config/Provider/ShippingOptions.php @@ -57,6 +57,7 @@ class ShippingOptions extends AbstractConfigProvider const XPATH_ITEM_OPTIONS_MANAGE_STOCK = 'cataloginventory/item_options/manage_stock'; const XPATH_SHIPPING_OPTION_CARGO_ACTIVE = 'tig_postnl/cargo/cargo_active'; const XPATH_SHIPPING_OPTION_EPS_BUSINESS_ACTIVE = 'tig_postnl/eps/business_active'; + const XPATH_SHIPPING_OPTIONS_PEPS_ACTIVE = 'tig_postnl/peps/active'; private $defaultMaxDeliverydays = '5'; @@ -241,6 +242,14 @@ public function canUseEpsBusinessProducts() { return (bool) $this->getConfigFromXpath(static::XPATH_SHIPPING_OPTION_EPS_BUSINESS_ACTIVE); } + + /** + * @return bool + */ + public function canUsePepsProducts() + { + return (bool) $this->getConfigFromXpath(static::XPATH_SHIPPING_OPTIONS_PEPS_ACTIVE); + } } /** * @codingStandardsIgnoreEnd diff --git a/Config/Source/Options/DefaultOptions.php b/Config/Source/Options/DefaultOptions.php index 70e4d1a11..787fa8045 100644 --- a/Config/Source/Options/DefaultOptions.php +++ b/Config/Source/Options/DefaultOptions.php @@ -114,14 +114,33 @@ public function getEpsProducts() ['isEvening' => false, 'countryLimitation' => false, 'group' => 'eu_options'] ); - $epsBusinessOptions = []; + if ($this->shippingOptions->canUsePepsProducts()) { + $pepsOptions = $this->productOptions->getProductoptions(['group' => 'peps_options']); + $epsOptions = array_merge($epsOptions, $pepsOptions); + } + if ($this->shippingOptions->canUseEpsBusinessProducts()) { $epsBusinessOptions = $this->productOptions->getProductoptions( ['isEvening' => false, 'countryLimitation' => false, 'group' => 'eps_package_options'] ); + $epsOptions = array_merge($epsOptions, $epsBusinessOptions); + } + + return $epsOptions; + } + + /** + * @return array + */ + public function getGlobalProducts() + { + $globalOptions = $this->productOptions->getProductoptions(['group' => 'global_options']); + if ($this->shippingOptions->canUsePepsProducts()) { + $pepsOptions = $this->productOptions->getProductoptions(['group' => 'peps_options']); + $globalOptions = array_merge($globalOptions, $pepsOptions); } - return array_merge($epsOptions, $epsBusinessOptions); + return $globalOptions; } /** diff --git a/Config/Source/OptionsAbstract.php b/Config/Source/OptionsAbstract.php index c904436ca..c902ef99c 100644 --- a/Config/Source/OptionsAbstract.php +++ b/Config/Source/OptionsAbstract.php @@ -594,6 +594,47 @@ abstract class OptionsAbstract 'countryLimitation' => false, 'group' => 'eps_package_options', ], + // PEPS Products + '6350' => [ + 'value' => '6350', + 'label' => 'Priority product 1', + 'isExtraCover' => false, + 'isEvening' => false, + 'isSunday' => false, + 'isGuaranteedDelivery' => false, + 'countryLimitation' => false, + 'group' => 'peps_options', + ], + '6550' => [ + 'value' => '6550', + 'label' => 'Priority product 2', + 'isExtraCover' => false, + 'isEvening' => false, + 'isSunday' => false, + 'isGuaranteedDelivery' => false, + 'countryLimitation' => false, + 'group' => 'peps_options', + ], + '6940' => [ + 'value' => '6940', + 'label' => 'Priority product 3', + 'isExtraCover' => false, + 'isEvening' => false, + 'isSunday' => false, + 'isGuaranteedDelivery' => false, + 'countryLimitation' => false, + 'group' => 'peps_options', + ], + '6942' => [ + 'value' => '6942', + 'label' => 'Priority product 4', + 'isExtraCover' => false, + 'isEvening' => false, + 'isSunday' => false, + 'isGuaranteedDelivery' => false, + 'countryLimitation' => false, + 'group' => 'peps_options', + ] ]; protected $groups = [ @@ -606,7 +647,8 @@ abstract class OptionsAbstract 'id_check_options' => 'ID Check options', 'id_check_pakjegemak_options' => 'ID Check Post Office options', 'cargo_options' => 'Cargo options', - 'eps_package_options' => 'Package options' + 'eps_package_options' => 'Package options', + 'peps_products' => 'Priority EPS' ]; protected $groupToLabel = [ @@ -619,7 +661,8 @@ abstract class OptionsAbstract 'id_check_options' => 'ID Check', 'id_check_pakjegemak_options' => 'ID Check Post Office', 'cargo_options' => 'Cargo', - 'eps_package_options' => 'Package' + 'eps_package_options' => 'Package', + 'peps_products' => 'Priority (EPS / Globalpack)' ]; protected $typeToComment = [ diff --git a/Service/Handler/BarcodeHandler.php b/Service/Handler/BarcodeHandler.php index e9ec996de..89834ece6 100644 --- a/Service/Handler/BarcodeHandler.php +++ b/Service/Handler/BarcodeHandler.php @@ -39,6 +39,7 @@ use TIG\PostNL\Webservices\Endpoints\Barcode as BarcodeEndpoint; use TIG\PostNL\Model\ResourceModel\ShipmentBarcode\CollectionFactory; use \Magento\Framework\Exception\LocalizedException; +use TIG\PostNL\Config\Provider\ProductOptions as ProductOptionsConfiguration; class BarcodeHandler { @@ -67,6 +68,11 @@ class BarcodeHandler */ private $countryId; + /** + * @var ProductOptionsConfiguration + */ + private $productOptionsConfiguration; + /** * $var null|int */ @@ -77,17 +83,20 @@ class BarcodeHandler * @param ShipmentRepositoryInterface $shipmentRepository * @param ShipmentBarcodeFactory $shipmentBarcodeFactory * @param CollectionFactory $shipmentBarcodeCollectionFactory + * @param ProductOptionsConfiguration $productOptionsConfiguration */ public function __construct( BarcodeEndpoint $barcodeEndpoint, ShipmentRepositoryInterface $shipmentRepository, ShipmentBarcodeFactory $shipmentBarcodeFactory, - CollectionFactory $shipmentBarcodeCollectionFactory + CollectionFactory $shipmentBarcodeCollectionFactory, + ProductOptionsConfiguration $productOptionsConfiguration ) { $this->barcodeEndpoint = $barcodeEndpoint; $this->shipmentBarcodeCollectionFactory = $shipmentBarcodeCollectionFactory; $this->shipmentBarcodeFactory = $shipmentBarcodeFactory; $this->shipmentRepository = $shipmentRepository; + $this->productOptionsConfiguration = $productOptionsConfiguration; } /** @@ -106,7 +115,7 @@ public function prepareShipment($magentoShipmentId, $countryId) $magentoShipment = $shipment->getShipment(); $this->storeId = $magentoShipment->getStoreId(); - $mainBarcode = $this->generate(); + $mainBarcode = $this->generate($shipment); $shipment->setMainBarcode($mainBarcode); $this->shipmentRepository->save($shipment); @@ -136,7 +145,7 @@ public function addBarcodes(ShipmentInterface $shipment, $mainBarcode) $parcelCount = $shipment->getParcelCount(); for ($count = 2; $count <= $parcelCount; $count++) { - $barcodeModelCollection->addItem($this->createBarcode($shipment->getId(), $count, $this->generate())); + $barcodeModelCollection->addItem($this->createBarcode($shipment->getId(), $count, $this->generate($shipment))); } $barcodeModelCollection->save(); @@ -145,13 +154,16 @@ public function addBarcodes(ShipmentInterface $shipment, $mainBarcode) /** * CIF call to generate a new barcode * + * @param ShipmentInterface $shipment + * * @return string * @throws \Magento\Framework\Exception\LocalizedException */ - private function generate() + private function generate(ShipmentInterface $shipment) { $this->barcodeEndpoint->setCountryId($this->countryId); $this->barcodeEndpoint->setStoreId($this->storeId); + $this->setTypeByProductCode($shipment->getProductCode()); $response = $this->barcodeEndpoint->call(); if (!is_object($response) || !isset($response->Barcode)) { @@ -164,6 +176,18 @@ private function generate() return (string) $response->Barcode; } + /** + * @param $code + */ + private function setTypeByProductCode($code) + { + if ($this->productOptionsConfiguration->checkProductByFlags($code, 'group', 'peps_options')) { + $this->barcodeEndpoint->setType('PEPS'); + } + + $this->barcodeEndpoint->setType(''); + } + /** * @param $shipmentId * @param $count diff --git a/Service/Order/ProductCodeAndType.php b/Service/Order/ProductCodeAndType.php index 8ee668741..b3f0c69ba 100644 --- a/Service/Order/ProductCodeAndType.php +++ b/Service/Order/ProductCodeAndType.php @@ -218,10 +218,7 @@ private function getEpsOption($address) */ private function getGlobalPackOption() { - $options = $this->productOptionsFinder->getGlobalPackOptions(); - $firstOption = array_shift($options); - - $this->code = $firstOption['value']; + $this->code = $this->productOptionsConfiguration->getDefaultGlobalpackOption(); $this->type = static::SHIPMENT_TYPE_GP; } diff --git a/Service/Shipment/Barcode/Range.php b/Service/Shipment/Barcode/Range.php index 6051832ec..827608cb8 100644 --- a/Service/Shipment/Barcode/Range.php +++ b/Service/Shipment/Barcode/Range.php @@ -33,7 +33,7 @@ use TIG\PostNL\Config\Provider\AccountConfiguration; use TIG\PostNL\Config\Provider\Globalpack; - +use TIG\PostNL\Config\Provider\PepsConfiguration; use TIG\PostNL\Exception as PostnlException; use TIG\PostNL\Service\Shipment\EpsCountries; @@ -58,6 +58,11 @@ class Range */ private $globalpackConfiguration; + /** + * @var PepsConfiguration + */ + private $pepsConfiguration; + /** * @var int */ @@ -66,13 +71,16 @@ class Range /** * @param AccountConfiguration $accountConfiguration * @param Globalpack $globalpack + * @param PepsConfiguration $pepsConfiguration */ public function __construct( AccountConfiguration $accountConfiguration, - Globalpack $globalpack + Globalpack $globalpack, + PepsConfiguration $pepsConfiguration ) { $this->accountConfiguration = $accountConfiguration; $this->globalpackConfiguration = $globalpack; + $this->pepsConfiguration = $pepsConfiguration; } /** @@ -97,13 +105,18 @@ public function get($barcodeType) /** * @param $countryId * @param $storeId + * @param $type * * @return array */ - public function getByCountryId($countryId, $storeId = null) + public function getByCountryId($countryId, $storeId = null, $type = '') { $this->storeId = $storeId; + if ($type && $type == 'PEPS') { + return $this->get('PEPS'); + } + if ($countryId == 'NL') { return $this->get('NL'); } @@ -171,6 +184,22 @@ private function getGlobalBarcode() ]; } + /** + * @return array + */ + private function getPepsBarcode() + { + $type = $this->pepsConfiguration->getBarcodeType(); + $range = $this->pepsConfiguration->getBarcodeRange(); + $serie = static::EU_BARCODE_SERIE_LONG; + + return [ + 'type' => $type, + 'range' => $range, + 'serie' => $serie, + ]; + } + /** * @param $barcodeData * @throws PostnlException @@ -205,6 +234,10 @@ private function getBarcodeData($barcodeType) return $this->getGlobalBarcode(); } + if ($barcodeType == 'PEPS') { + return $this->getPepsBarcode(); + } + $this->noBarcodeDataError($barcodeType); } diff --git a/Webservices/Endpoints/Barcode.php b/Webservices/Endpoints/Barcode.php index c0aa92aa7..6079009a1 100644 --- a/Webservices/Endpoints/Barcode.php +++ b/Webservices/Endpoints/Barcode.php @@ -80,6 +80,11 @@ class Barcode extends AbstractEndpoint */ private $countryId; + /** + * @var string + */ + private $type = ''; + /** * @param Soap $soap * @param BarcodeRange $barcodeRange @@ -105,7 +110,7 @@ public function call() { $this->validateRequiredValues(); - $barcode = $this->barcodeRange->getByCountryId($this->countryId, $this->storeId); + $barcode = $this->barcodeRange->getByCountryId($this->countryId, $this->storeId, $this->type); $parameters = [ 'Message' => $this->message->get(''), @@ -138,6 +143,14 @@ public function setCountryId($countryId) $this->countryId = $countryId; } + /** + * @param $type + */ + public function setType($type) + { + $this->type = $type; + } + /** * @param int $storeId */ diff --git a/Webservices/Endpoints/Labelling.php b/Webservices/Endpoints/Labelling.php index 12e6dfe2d..5b8fc052b 100644 --- a/Webservices/Endpoints/Labelling.php +++ b/Webservices/Endpoints/Labelling.php @@ -60,7 +60,7 @@ class Labelling extends AbstractEndpoint /** * @var string */ - private $version = 'v2_1'; + private $version = 'v2_2'; /** * @var string diff --git a/Webservices/Endpoints/LabellingWithoutConfirm.php b/Webservices/Endpoints/LabellingWithoutConfirm.php index ad30f5b54..1b5f5f361 100644 --- a/Webservices/Endpoints/LabellingWithoutConfirm.php +++ b/Webservices/Endpoints/LabellingWithoutConfirm.php @@ -60,7 +60,7 @@ class LabellingWithoutConfirm extends AbstractEndpoint /** * @var string */ - private $version = 'v2_1'; + private $version = 'v2_2'; /** * @var string diff --git a/etc/adminhtml/system/globalpack.xml b/etc/adminhtml/system/globalpack.xml index 87427904b..ca0d705b5 100644 --- a/etc/adminhtml/system/globalpack.xml +++ b/etc/adminhtml/system/globalpack.xml @@ -41,12 +41,19 @@ \TIG\PostNL\Block\Adminhtml\Config\Globalpack\UsingGlobalpack - + Worldwide shipping uses the PostNL GlobalPack product. Magento\Config\Model\Config\Source\Yesno tig_postnl/globalpack/enabled + + + + TIG\PostNL\Config\Source\Options\DefaultOptions::getGlobalProducts + tig_postnl/globalpack/default_gp_option + + tig_postnl-sub-section diff --git a/etc/adminhtml/system/postnlsettings.xml b/etc/adminhtml/system/postnlsettings.xml index 28ddd489d..9449e7526 100644 --- a/etc/adminhtml/system/postnlsettings.xml +++ b/etc/adminhtml/system/postnlsettings.xml @@ -204,6 +204,7 @@ + diff --git a/etc/adminhtml/system/postnlsettings/peps.xml b/etc/adminhtml/system/postnlsettings/peps.xml new file mode 100644 index 000000000..abdd40ac1 --- /dev/null +++ b/etc/adminhtml/system/postnlsettings/peps.xml @@ -0,0 +1,57 @@ + + + + + + + + TIG\PostNL\Block\Adminhtml\Config\Form\Field\Fieldset + tig_postnl-sub-sub-section + + + These products can only be used for an order which contains five or more parcels (colli). Each of these parcels should have a maximum weight of 2kg. + + Magento\Config\Model\Config\Source\Yesno + tig_postnl/peps/active + + + + The current PEPS barcode type as supplied by PostNL. Must contain 2 letters. + tig_postnl/peps/barcode_type + + 1 + + + + diff --git a/etc/config.xml b/etc/config.xml index 42c8d1c2c..66c215df8 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -164,6 +164,12 @@ + + 0 + LA + NL + + From da66d73c44da4f25e8a7863bf0151876855aa52e Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Mon, 31 Dec 2018 11:14:37 +0100 Subject: [PATCH 002/113] Fixed unit test --- Test/Unit/Service/Handler/BarcodeHandlerTest.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Test/Unit/Service/Handler/BarcodeHandlerTest.php b/Test/Unit/Service/Handler/BarcodeHandlerTest.php index a5c3eee46..421c88a64 100644 --- a/Test/Unit/Service/Handler/BarcodeHandlerTest.php +++ b/Test/Unit/Service/Handler/BarcodeHandlerTest.php @@ -34,6 +34,7 @@ use Magento\Framework\Phrase; use TIG\PostNL\Service\Handler\BarcodeHandler; use TIG\PostNL\Test\TestCase; +use TIG\PostNL\Api\Data\ShipmentInterface; class BarcodeHandlerTest extends TestCase { @@ -63,7 +64,7 @@ public function testGenerate($callReturnValue, $expected) $barcodeMock = $this->getBarcodeMock($callReturnValue); $instance = $this->getInstance(['barcodeEndpoint' => $barcodeMock]); - $result = $this->invoke('generate', $instance); + $result = $this->invokeArgs('generate', [$this->getShippmentMock()], $instance); if ($result instanceof Phrase) { $result = $result->render(); @@ -79,7 +80,7 @@ public function testShouldThrowExceptionWhenInvalidResponse() try { $instance = $this->getInstance(['barcodeEndpoint' => $barcodeMock]); - $result = $this->invoke('generate', $instance); + $result = $this->invokeArgs('generate', [$this->getShippmentMock()], $instance); if ($result instanceof Phrase) { $result->render(); } @@ -88,6 +89,14 @@ public function testShouldThrowExceptionWhenInvalidResponse() } } + protected function getShippmentMock() + { + $shipmentMock = $this->getFakeMock(ShipmentInterface::class)->getMock(); + $shipmentMock->method('getProductCode')->willReturn('3085'); + + return $shipmentMock; + } + /** * @param $callReturnValue * From bd151a015e54f490052543eea81f72cacd54b7b8 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Mon, 31 Dec 2018 14:07:46 +0100 Subject: [PATCH 003/113] Refactored barcode range getter --- Service/Handler/BarcodeHandler.php | 16 +-- Service/Shipment/Barcode/Range.php | 168 ++++++++++------------------- 2 files changed, 65 insertions(+), 119 deletions(-) diff --git a/Service/Handler/BarcodeHandler.php b/Service/Handler/BarcodeHandler.php index 89834ece6..54c1b5929 100644 --- a/Service/Handler/BarcodeHandler.php +++ b/Service/Handler/BarcodeHandler.php @@ -63,21 +63,21 @@ class BarcodeHandler */ private $shipmentRepository; - /** - * @var string - */ - private $countryId; - /** * @var ProductOptionsConfiguration */ private $productOptionsConfiguration; /** - * $var null|int + * $var int */ private $storeId; + /** + * @var string + */ + private $countryId; + /** * @param BarcodeEndpoint $barcodeEndpoint * @param ShipmentRepositoryInterface $shipmentRepository @@ -145,7 +145,9 @@ public function addBarcodes(ShipmentInterface $shipment, $mainBarcode) $parcelCount = $shipment->getParcelCount(); for ($count = 2; $count <= $parcelCount; $count++) { - $barcodeModelCollection->addItem($this->createBarcode($shipment->getId(), $count, $this->generate($shipment))); + $barcodeModelCollection->addItem( + $this->createBarcode($shipment->getId(), $count, $this->generate($shipment)) + ); } $barcodeModelCollection->save(); diff --git a/Service/Shipment/Barcode/Range.php b/Service/Shipment/Barcode/Range.php index 827608cb8..f9f2666bf 100644 --- a/Service/Shipment/Barcode/Range.php +++ b/Service/Shipment/Barcode/Range.php @@ -68,6 +68,15 @@ class Range */ private $storeId; + /** + * @var array + */ + private $response = [ + 'type' => '', + 'range' => '', + 'serie' => '' + ]; + /** * @param AccountConfiguration $accountConfiguration * @param Globalpack $globalpack @@ -84,37 +93,29 @@ public function __construct( } /** - * Gets data for the barcode that's requested. Depending on the destination of the shipment several barcode types - * may be requested. + * @param $barcodeType * - * @param string $barcodeType * @return array - * @throws PostnlException */ public function get($barcodeType) { - $barcodeType = strtoupper($barcodeType); - - $barcodeData = $this->getBarcodeData($barcodeType); - - $this->validateBarcodeData($barcodeData); - - return $barcodeData; + $this->set($barcodeType); + return $this->response; } /** - * @param $countryId - * @param $storeId - * @param $type + * @param $countryId + * @param null $storeId + * @param string $type * - * @return array + * @return array|string */ public function getByCountryId($countryId, $storeId = null, $type = '') { $this->storeId = $storeId; - if ($type && $type == 'PEPS') { - return $this->get('PEPS'); + if ($type) { + return $this->get($type); } if ($countryId == 'NL') { @@ -125,120 +126,63 @@ public function getByCountryId($countryId, $storeId = null, $type = '') return $this->get('EU'); } - return $this->get('global'); + return $this->get('GLOBAL'); } /** - * @return array + * @param $type */ - private function getNlBarcode() + public function set($type) { - $type = '3S'; - $range = $this->accountConfiguration->getCustomerCode($this->storeId); - $serie = static::NL_BARCODE_SERIE_LONG; - - if (strlen($range) > 3) { - $serie = static::NL_BARCODE_SERIE_SHORT; + $this->response['type'] = '3S'; + $this->response['range'] = $this->accountConfiguration->getCustomerCode($this->storeId); + switch (strtoupper($type)) { + case 'NL' : + $this->setNlSerie(); + break; + case 'EU' : + $this->setEuSerie(); + break; + case 'GLOBAL' : + $this->setGlobalPackOptions(); + break; + case 'PEPS' : + $this->setPepsOptions(); + break; + default: + $this->noBarcodeDataError($type); + break; } - - return [ - 'type' => $type, - 'range' => $range, - 'serie' => $serie, - ]; } - /** - * @return array - */ - private function getEuBarcode() + private function setNlSerie() { - $type = '3S'; - $range = $this->accountConfiguration->getCustomerCode($this->storeId); - $serie = static::EU_BARCODE_SERIE_LONG; - - if (strlen($range) > 3) { - $serie = static::EU_BARCODE_SERIE_SHORT; + $this->response['serie'] = static::NL_BARCODE_SERIE_LONG; + if (strlen($this->response['range']) > 3) { + $this->response['serie'] = static::NL_BARCODE_SERIE_SHORT; } - - return [ - 'type' => $type, - 'range' => $range, - 'serie' => $serie, - ]; - } - - /** - * @return array - */ - private function getGlobalBarcode() - { - $type = $this->globalpackConfiguration->getBarcodeType(); - $range = $this->globalpackConfiguration->getBarcodeRange(); - $serie = static::GLOBAL_BARCODE_SERIE; - - return [ - 'type' => $type, - 'range' => $range, - 'serie' => $serie, - ]; } - /** - * @return array - */ - private function getPepsBarcode() + private function setEuSerie() { - $type = $this->pepsConfiguration->getBarcodeType(); - $range = $this->pepsConfiguration->getBarcodeRange(); - $serie = static::EU_BARCODE_SERIE_LONG; - - return [ - 'type' => $type, - 'range' => $range, - 'serie' => $serie, - ]; + $this->response['serie'] = static::EU_BARCODE_SERIE_LONG; + if (strlen($this->response['range']) > 3) { + $this->response['serie'] = static::EU_BARCODE_SERIE_SHORT; + } } - /** - * @param $barcodeData - * @throws PostnlException - */ - private function validateBarcodeData($barcodeData) + private function setGlobalPackOptions() { - if (!$barcodeData['type'] || !$barcodeData['range']) { - throw new PostnlException( - // @codingStandardsIgnoreLine - __('Unable to retrieve barcode data.'), - 'POSTNL-0111' - ); - } + $this->response['type'] = $this->globalpackConfiguration->getBarcodeType(); + $this->response['range'] = $this->globalpackConfiguration->getBarcodeRange(); + $this->response['serie'] = static::GLOBAL_BARCODE_SERIE; } - /** - * @param $barcodeType - * @return array - * @throws PostnlException - */ - private function getBarcodeData($barcodeType) + private function setPepsOptions() { - if ($barcodeType == 'NL') { - return $this->getNlBarcode(); - } - - if ($barcodeType == 'EU') { - return $this->getEuBarcode(); - } - - if ($barcodeType == 'GLOBAL') { - return $this->getGlobalBarcode(); - } - - if ($barcodeType == 'PEPS') { - return $this->getPepsBarcode(); - } - - $this->noBarcodeDataError($barcodeType); + $this->response['type'] = $this->pepsConfiguration->getBarcodeType(); + $this->response['range'] = $this->pepsConfiguration->getBarcodeRange(); + $this->response['serie'] = static::EU_BARCODE_SERIE_LONG; } /** From fa1ddf6df06c1f614a1e95e32a6fb5c0bb97e846 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Mon, 31 Dec 2018 14:52:54 +0100 Subject: [PATCH 004/113] Fixed codesniffer bugs --- Service/Handler/BarcodeHandler.php | 2 +- Service/Order/ProductCodeAndType.php | 3 +-- Service/Shipment/Barcode/Range.php | 10 ++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Service/Handler/BarcodeHandler.php b/Service/Handler/BarcodeHandler.php index 54c1b5929..c9302f200 100644 --- a/Service/Handler/BarcodeHandler.php +++ b/Service/Handler/BarcodeHandler.php @@ -69,7 +69,7 @@ class BarcodeHandler private $productOptionsConfiguration; /** - * $var int + * $var string */ private $storeId; diff --git a/Service/Order/ProductCodeAndType.php b/Service/Order/ProductCodeAndType.php index b3f0c69ba..21295c295 100644 --- a/Service/Order/ProductCodeAndType.php +++ b/Service/Order/ProductCodeAndType.php @@ -208,8 +208,7 @@ private function getEpsOption($address) $this->type = static::SHIPMENT_TYPE_EPS; // Force type Global Pack (mainly used for Canary Islands) if (in_array('4945', $firstOption)) { - $this->code = $firstOption; - $this->type = static::SHIPMENT_TYPE_GP; + $this->getGlobalPackOption(); } } diff --git a/Service/Shipment/Barcode/Range.php b/Service/Shipment/Barcode/Range.php index f9f2666bf..e40c48a41 100644 --- a/Service/Shipment/Barcode/Range.php +++ b/Service/Shipment/Barcode/Range.php @@ -136,23 +136,25 @@ public function set($type) { $this->response['type'] = '3S'; $this->response['range'] = $this->accountConfiguration->getCustomerCode($this->storeId); + // @codingStandardsIgnoreStart switch (strtoupper($type)) { - case 'NL' : + case 'NL': $this->setNlSerie(); break; - case 'EU' : + case 'EU': $this->setEuSerie(); break; - case 'GLOBAL' : + case 'GLOBAL': $this->setGlobalPackOptions(); break; - case 'PEPS' : + case 'PEPS': $this->setPepsOptions(); break; default: $this->noBarcodeDataError($type); break; } + // @codingStandardsIgnoreEnd } private function setNlSerie() From b455ce2ea41e0382c242de7c0c0017797c5a70e3 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Mon, 31 Dec 2018 15:13:02 +0100 Subject: [PATCH 005/113] Test codesniffer methods --- Service/Handler/BarcodeHandler.php | 12 +++--------- Service/Shipment/Barcode/Range.php | 16 +++++++--------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Service/Handler/BarcodeHandler.php b/Service/Handler/BarcodeHandler.php index c9302f200..543109661 100644 --- a/Service/Handler/BarcodeHandler.php +++ b/Service/Handler/BarcodeHandler.php @@ -68,11 +68,6 @@ class BarcodeHandler */ private $productOptionsConfiguration; - /** - * $var string - */ - private $storeId; - /** * @var string */ @@ -112,9 +107,6 @@ public function prepareShipment($magentoShipmentId, $countryId) return; } - $magentoShipment = $shipment->getShipment(); - $this->storeId = $magentoShipment->getStoreId(); - $mainBarcode = $this->generate($shipment); $shipment->setMainBarcode($mainBarcode); $this->shipmentRepository->save($shipment); @@ -163,8 +155,10 @@ public function addBarcodes(ShipmentInterface $shipment, $mainBarcode) */ private function generate(ShipmentInterface $shipment) { + $magentoShipment = $shipment->getShipment(); + $this->barcodeEndpoint->setCountryId($this->countryId); - $this->barcodeEndpoint->setStoreId($this->storeId); + $this->barcodeEndpoint->setStoreId($magentoShipment->getStoreId()); $this->setTypeByProductCode($shipment->getProductCode()); $response = $this->barcodeEndpoint->call(); diff --git a/Service/Shipment/Barcode/Range.php b/Service/Shipment/Barcode/Range.php index e40c48a41..c90dc178c 100644 --- a/Service/Shipment/Barcode/Range.php +++ b/Service/Shipment/Barcode/Range.php @@ -99,7 +99,7 @@ public function __construct( */ public function get($barcodeType) { - $this->set($barcodeType); + $this->set(strtoupper($barcodeType)); return $this->response; } @@ -136,25 +136,23 @@ public function set($type) { $this->response['type'] = '3S'; $this->response['range'] = $this->accountConfiguration->getCustomerCode($this->storeId); - // @codingStandardsIgnoreStart - switch (strtoupper($type)) { + switch ($type) { case 'NL': $this->setNlSerie(); - break; + return; case 'EU': $this->setEuSerie(); - break; + return; case 'GLOBAL': $this->setGlobalPackOptions(); - break; + return; case 'PEPS': $this->setPepsOptions(); - break; + return; default: $this->noBarcodeDataError($type); - break; + return; } - // @codingStandardsIgnoreEnd } private function setNlSerie() From d0d4a869d0377729273d011dec425661642e5f17 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Mon, 31 Dec 2018 15:34:05 +0100 Subject: [PATCH 006/113] Fixed codesniffer bug --- Service/Shipment/Barcode/Range.php | 5 ++--- Test/Unit/Service/Handler/BarcodeHandlerTest.php | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Service/Shipment/Barcode/Range.php b/Service/Shipment/Barcode/Range.php index c90dc178c..4f49a3e43 100644 --- a/Service/Shipment/Barcode/Range.php +++ b/Service/Shipment/Barcode/Range.php @@ -149,10 +149,9 @@ public function set($type) case 'PEPS': $this->setPepsOptions(); return; - default: - $this->noBarcodeDataError($type); - return; } + + $this->noBarcodeDataError($type); } private function setNlSerie() diff --git a/Test/Unit/Service/Handler/BarcodeHandlerTest.php b/Test/Unit/Service/Handler/BarcodeHandlerTest.php index 421c88a64..a667360b2 100644 --- a/Test/Unit/Service/Handler/BarcodeHandlerTest.php +++ b/Test/Unit/Service/Handler/BarcodeHandlerTest.php @@ -91,8 +91,12 @@ public function testShouldThrowExceptionWhenInvalidResponse() protected function getShippmentMock() { + $magentoShipmentMock = $this->getFakeMock('\Magento\Sales\Api\Data\ShipmentInterface')->getMock(); + $magentoShipmentMock->method('getStoreId')->willReturn(0); + $shipmentMock = $this->getFakeMock(ShipmentInterface::class)->getMock(); $shipmentMock->method('getProductCode')->willReturn('3085'); + $shipmentMock->method('getShipment')->willReturn($magentoShipmentMock); return $shipmentMock; } From 5b0f0c789a6092e3cbe087d787bd4405a38aadd9 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Thu, 3 Jan 2019 13:54:22 +0100 Subject: [PATCH 007/113] POSTNLM2-725 - Added error handeling to peps confirmation --- Config/Provider/ShippingOptions.php | 9 ++ Controller/Adminhtml/LabelAbstract.php | 15 +++ .../Shipment/ConfirmAndPrintShippingLabel.php | 4 + .../Adminhtml/Shipment/PrintShippingLabel.php | 4 + Service/Shipment/Label/Validator.php | 98 +++++++++++++++++++ Service/Shipment/Labelling/GetLabels.php | 4 + etc/adminhtml/system/globalpack.xml | 3 + 7 files changed, 137 insertions(+) diff --git a/Config/Provider/ShippingOptions.php b/Config/Provider/ShippingOptions.php index 460f2e0fa..481c67cd6 100644 --- a/Config/Provider/ShippingOptions.php +++ b/Config/Provider/ShippingOptions.php @@ -58,6 +58,7 @@ class ShippingOptions extends AbstractConfigProvider const XPATH_SHIPPING_OPTION_CARGO_ACTIVE = 'tig_postnl/cargo/cargo_active'; const XPATH_SHIPPING_OPTION_EPS_BUSINESS_ACTIVE = 'tig_postnl/eps/business_active'; const XPATH_SHIPPING_OPTIONS_PEPS_ACTIVE = 'tig_postnl/peps/active'; + const XPATH_SHIPPING_OPTIONS_GLOBALPACK_ACTIVE = 'tig_postnl/globalpack/enabled'; private $defaultMaxDeliverydays = '5'; @@ -250,6 +251,14 @@ public function canUsePepsProducts() { return (bool) $this->getConfigFromXpath(static::XPATH_SHIPPING_OPTIONS_PEPS_ACTIVE); } + + /** + * @return bool + */ + public function canUseGlobalPack() + { + return (bool) $this->getConfigFromXpath(static::XPATH_SHIPPING_OPTIONS_GLOBALPACK_ACTIVE); + } } /** * @codingStandardsIgnoreEnd diff --git a/Controller/Adminhtml/LabelAbstract.php b/Controller/Adminhtml/LabelAbstract.php index 071152113..b39d611cf 100644 --- a/Controller/Adminhtml/LabelAbstract.php +++ b/Controller/Adminhtml/LabelAbstract.php @@ -118,6 +118,10 @@ public function __construct( protected function setLabel($shipmentId) { $labels = $this->getLabels->get($shipmentId); + if (isset($labels['errors'])) { + $this->handelRequestErrors($labels['errors']); + return; + } if (empty($labels)) { return; @@ -153,4 +157,15 @@ protected function setTracks($shipment) $this->track->set($shipment); } } + + /** + * @param $errors + */ + //@codingStandardsIgnoreLine + protected function handelRequestErrors($errors) + { + foreach ($errors as $error) { + $this->messageManager->addWarningMessage($error); + } + } } diff --git a/Controller/Adminhtml/Shipment/ConfirmAndPrintShippingLabel.php b/Controller/Adminhtml/Shipment/ConfirmAndPrintShippingLabel.php index 89ac1f306..f0e5aabf0 100644 --- a/Controller/Adminhtml/Shipment/ConfirmAndPrintShippingLabel.php +++ b/Controller/Adminhtml/Shipment/ConfirmAndPrintShippingLabel.php @@ -93,6 +93,10 @@ public function __construct( public function execute() { $labels = $this->getLabels(); + if (isset($labels['errors'])) { + $this->handelRequestErrors($labels['errors']); + return $this->_redirect($this->_redirect->getRefererUrl()); + } if (empty($labels)) { $this->messageManager->addErrorMessage( diff --git a/Controller/Adminhtml/Shipment/PrintShippingLabel.php b/Controller/Adminhtml/Shipment/PrintShippingLabel.php index 878b3e6de..d93f54634 100644 --- a/Controller/Adminhtml/Shipment/PrintShippingLabel.php +++ b/Controller/Adminhtml/Shipment/PrintShippingLabel.php @@ -85,6 +85,10 @@ public function __construct( public function execute() { $labels = $this->getLabels(); + if (isset($labels['errors'])) { + $this->handelRequestErrors($labels['errors']); + return $this->_redirect($this->_redirect->getRefererUrl()); + } if (empty($labels)) { $this->messageManager->addErrorMessage( diff --git a/Service/Shipment/Label/Validator.php b/Service/Shipment/Label/Validator.php index 89f9bc929..962fcb3ca 100644 --- a/Service/Shipment/Label/Validator.php +++ b/Service/Shipment/Label/Validator.php @@ -32,9 +32,41 @@ namespace TIG\PostNL\Service\Shipment\Label; use TIG\PostNL\Api\Data\ShipmentLabelInterface; +use TIG\PostNL\Api\Data\ShipmentInterface; +use TIG\PostNL\Config\Provider\ProductOptions; +use TIG\PostNL\Config\Provider\ShippingOptions; class Validator { + /** + * @var ProductOptions + */ + private $productOptions; + + /** + * @var ShippingOptions + */ + private $shippingOptions; + + /** + * @var array + */ + private $errors = []; + + /** + * Validator constructor. + * + * @param ProductOptions $productOptions + * @param ShippingOptions $shippingOptions + */ + public function __construct( + ProductOptions $productOptions, + ShippingOptions $shippingOptions + ) { + $this->productOptions = $productOptions; + $this->shippingOptions = $shippingOptions; + } + /** * Removes all labels that are empty or not a string. If a shipment has no valid labels, the shipment will be * removed from the stack. @@ -53,6 +85,72 @@ public function validate($input) return array_values($filtered); } + /** + * @param ShipmentInterface $shipment + * + * @return bool + */ + public function canRequest(ShipmentInterface $shipment) + { + if ($shipment->isGlobalPack()) { + return $this->validateGlobalPack($shipment); + } + + return $this->validateProductCode($shipment); + } + + /** + * @return array + */ + public function getErrors() + { + return $this->errors; + } + + /** + * @param $shipment + * + * @return bool + */ + private function validateGlobalPack(ShipmentInterface $shipment) + { + if (!$this->shippingOptions->canUseGlobalPack()) { + $magentoShipment = $shipment->getShipment(); + // @codingStandardsIgnoreLine + $this->errors[] = __('Could not print labels for shipment %1. Worldwide (Globalpack) Delivery is disabled. Please contact your PostNL account manager before you enable this method.', $magentoShipment->getIncrementId()); + return false; + } + + return $this->validateProductCode($shipment); + } + + /** + * @param $shipment + * + * @return bool + */ + private function validateProductCode(ShipmentInterface $shipment) + { + $code = $shipment->getProductCode(); + $isPeps = $this->productOptions->checkProductByFlags($code, 'group', 'peps_options'); + + if ($isPeps && !$this->shippingOptions->canUsePepsProducts()) { + $magentoShipment = $shipment->getShipment(); + // @codingStandardsIgnoreLine + $this->errors[] = __('Could not print labels for shipment %1. Priority Delivery is disabled. Please contact your PostNL account manager before you enable this method.', $magentoShipment->getIncrementId()); + return false; + } + + if ($isPeps && $shipment->getParcelCount() < 5) { + $magentoShipment = $shipment->getShipment(); + // @codingStandardsIgnoreLine + $this->errors[] = __('Could not print labels for shipment %1. Priority Delivery requires a minimum of parcels/colli.', $magentoShipment->getIncrementId()); + return false; + } + + return true; + } + /** * @param ShipmentLabelInterface|null $model * diff --git a/Service/Shipment/Labelling/GetLabels.php b/Service/Shipment/Labelling/GetLabels.php index 2e62c8f5d..de5108635 100644 --- a/Service/Shipment/Labelling/GetLabels.php +++ b/Service/Shipment/Labelling/GetLabels.php @@ -99,6 +99,10 @@ public function get($shipmentId, $confirm = true) return []; } + if (!$this->labelValidator->canRequest($shipment)) { + return ['errors' => $this->labelValidator->getErrors()]; + } + $labels = $this->getLabels($shipment, $confirm); $labels = $this->labelValidator->validate($labels); diff --git a/etc/adminhtml/system/globalpack.xml b/etc/adminhtml/system/globalpack.xml index ca0d705b5..fcfbbf05f 100644 --- a/etc/adminhtml/system/globalpack.xml +++ b/etc/adminhtml/system/globalpack.xml @@ -52,6 +52,9 @@ TIG\PostNL\Config\Source\Options\DefaultOptions::getGlobalProducts tig_postnl/globalpack/default_gp_option + + 1 + From 1c3a789094b66933e769040a43a605d61de4f728 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Wed, 9 Jan 2019 14:09:33 +0100 Subject: [PATCH 008/113] Peps changes --- Controller/Adminhtml/LabelAbstract.php | 4 +++ .../SetDefaultData.php | 1 - Service/Order/ProductCodeAndType.php | 26 +++++++++++-------- Service/Shipment/EpsCountries.php | 2 -- .../Shipment/Packingslip/GetPackingslip.php | 2 +- .../Shipment/Packingslip/MergeWithLabels.php | 8 +++--- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Controller/Adminhtml/LabelAbstract.php b/Controller/Adminhtml/LabelAbstract.php index b39d611cf..dd7a048a9 100644 --- a/Controller/Adminhtml/LabelAbstract.php +++ b/Controller/Adminhtml/LabelAbstract.php @@ -139,6 +139,10 @@ protected function setLabel($shipmentId) protected function setPackingslip($shipmentId, $withLabels = true, $confirm = true) { $packingslip = $this->getPackingSlip->get($shipmentId, $withLabels, $confirm); + if (is_array($packingslip) && isset($packingslip['errors'])) { + $this->handelRequestErrors($packingslip['errors']); + return; + } if (strlen($packingslip) <= 0) { return; diff --git a/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php b/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php index 00d99ef00..3b83f3f28 100644 --- a/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php +++ b/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php @@ -201,7 +201,6 @@ private function getOptionFromQuote() private function checkByAddressData(OrderInterface $order) { $address = null; - $country = null; /** @noinspection PhpUndefinedMethodInspection */ $address = $order->getPgAddress(); diff --git a/Service/Order/ProductCodeAndType.php b/Service/Order/ProductCodeAndType.php index 863bf2f62..c6a712814 100644 --- a/Service/Order/ProductCodeAndType.php +++ b/Service/Order/ProductCodeAndType.php @@ -101,16 +101,7 @@ public function __construct( // @codingStandardsIgnoreStart public function get($type = '', $option = '', $address = null) { - $country = null; - if ($address && is_object($address)) { - $country = $address->getCountryId(); - } - - if (is_string($address)) { - $country = $address; - } - - $country = $country ?: $this->getCountryCode(); + $country = $this->getCountryCode($address); $type = strtolower($type); $option = strtolower($option); @@ -234,10 +225,23 @@ private function response() } /** + * @param SalesAddress|QuoteAddress|string $address * @return string */ - private function getCountryCode() + private function getCountryCode($address) { + if ($address && is_object($address)) { + return $address->getCountryId(); + } + + /** + * \TIG\PostNL\Helper\DeliveryOptions\OrderParams::formatParamData + * Request is done with country code only. + */ + if (is_string($address)) { + return $address; + } + $address = $this->quote->getShippingAddress(); return $address->getCountryId(); } diff --git a/Service/Shipment/EpsCountries.php b/Service/Shipment/EpsCountries.php index d673bd70c..efbcff8b0 100644 --- a/Service/Shipment/EpsCountries.php +++ b/Service/Shipment/EpsCountries.php @@ -51,8 +51,6 @@ class EpsCountries * 'GL', // Greenland * * ==== SPAIN ==== - * @codingStandardsIgnoreLine - * @todo: Not in the Magento Country list, customer will use ES which will cause the shipment to be EPS. * 'IC', // Las Palmas, Santa Cruz and Melilla * * ==== Italy ==== diff --git a/Service/Shipment/Packingslip/GetPackingslip.php b/Service/Shipment/Packingslip/GetPackingslip.php index 9b58851af..8dfc087a0 100644 --- a/Service/Shipment/Packingslip/GetPackingslip.php +++ b/Service/Shipment/Packingslip/GetPackingslip.php @@ -92,7 +92,7 @@ public function __construct( * @param bool $withLabels * @param bool $confirm * - * @return string + * @return string|array */ public function get($shipmentId, $withLabels = true, $confirm = true) { diff --git a/Service/Shipment/Packingslip/MergeWithLabels.php b/Service/Shipment/Packingslip/MergeWithLabels.php index f8d090eee..22e7714e0 100644 --- a/Service/Shipment/Packingslip/MergeWithLabels.php +++ b/Service/Shipment/Packingslip/MergeWithLabels.php @@ -125,6 +125,10 @@ public function merge($shipmentId, $packingslip, $mergeFirstLabel = false, $conf return $packingslip; } + if (isset($labels['errors'])) { + return $labels['errors']; + } + if ($mergeFirstLabel && $this->canMergeFirstLabel($labels[0])) { $firstLabel = array_shift($labels); // @codingStandardsIgnoreLine @@ -132,10 +136,6 @@ public function merge($shipmentId, $packingslip, $mergeFirstLabel = false, $conf $packingslip = $this->mergeFirstLabel($label, $packingslip, $firstLabel->getType()); } - if (empty($labels)) { - return $packingslip; - } - $packingslipPdf = $this->addLabelsToPackingslip($packingslip, $labels); return $packingslipPdf; } From 916f5b5fb88ccaca5932130531270c929c55ac3e Mon Sep 17 00:00:00 2001 From: Kevin van Dijk Date: Thu, 10 Jan 2019 13:47:31 +0100 Subject: [PATCH 009/113] SDPOSTNL-10626 - Fixed an issue where street could be undefined --- view/frontend/web/js/Helper/AddressFinder.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/view/frontend/web/js/Helper/AddressFinder.js b/view/frontend/web/js/Helper/AddressFinder.js index b83dfd217..d75b00c62 100644 --- a/view/frontend/web/js/Helper/AddressFinder.js +++ b/view/frontend/web/js/Helper/AddressFinder.js @@ -95,9 +95,14 @@ define([ * The street is not always available on the first run. */ var shippingAddress = quote.shippingAddress(); - if (customer.isLoggedIn() && shippingAddress && shippingAddress.street) { + var quoteStreet = []; + if (shippingAddress) { + quoteStreet = (typeof shippingAddress.street === 'undefined') ? [] : shippingAddress.street; + } + + if (customer.isLoggedIn() && shippingAddress && quoteStreet.length > 0) { address = { - street: shippingAddress.street, + street: quoteStreet, postcode: shippingAddress.postcode, lastname: shippingAddress.lastname, firstname: shippingAddress.firstname, From f43e9ad44faadd77aa57d9e33860cde479712f02 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Fri, 18 Jan 2019 15:12:42 +0100 Subject: [PATCH 010/113] Added labels to PEPS products --- Config/Source/OptionsAbstract.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Config/Source/OptionsAbstract.php b/Config/Source/OptionsAbstract.php index c902ef99c..6ddd7350a 100644 --- a/Config/Source/OptionsAbstract.php +++ b/Config/Source/OptionsAbstract.php @@ -597,7 +597,7 @@ abstract class OptionsAbstract // PEPS Products '6350' => [ 'value' => '6350', - 'label' => 'Priority product 1', + 'label' => 'Priority packets tracked', 'isExtraCover' => false, 'isEvening' => false, 'isSunday' => false, @@ -607,7 +607,7 @@ abstract class OptionsAbstract ], '6550' => [ 'value' => '6550', - 'label' => 'Priority product 2', + 'label' => 'Priority packets tracked bulk', 'isExtraCover' => false, 'isEvening' => false, 'isSunday' => false, @@ -617,7 +617,7 @@ abstract class OptionsAbstract ], '6940' => [ 'value' => '6940', - 'label' => 'Priority product 3', + 'label' => 'Priority packets tracked sorted', 'isExtraCover' => false, 'isEvening' => false, 'isSunday' => false, @@ -627,7 +627,7 @@ abstract class OptionsAbstract ], '6942' => [ 'value' => '6942', - 'label' => 'Priority product 4', + 'label' => 'Priority packets tracked boxable', 'isExtraCover' => false, 'isEvening' => false, 'isSunday' => false, From 92e09b5497bd93dae9135faad2e341bdd24c939d Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Mon, 21 Jan 2019 10:27:26 +0100 Subject: [PATCH 011/113] POSTNLM2-741 - Added country lists for PEPS shipments --- Service/Shipment/PepsCountries.php | 96 ++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Service/Shipment/PepsCountries.php diff --git a/Service/Shipment/PepsCountries.php b/Service/Shipment/PepsCountries.php new file mode 100644 index 000000000..fce375989 --- /dev/null +++ b/Service/Shipment/PepsCountries.php @@ -0,0 +1,96 @@ + Date: Tue, 22 Jan 2019 14:12:42 +0100 Subject: [PATCH 012/113] Added peps check for product type repsonse --- Service/Order/ProductCodeAndType.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Service/Order/ProductCodeAndType.php b/Service/Order/ProductCodeAndType.php index c6a712814..1e53413c5 100644 --- a/Service/Order/ProductCodeAndType.php +++ b/Service/Order/ProductCodeAndType.php @@ -36,6 +36,7 @@ use Magento\Quote\Model\Quote\Address as QuoteAddress; use TIG\PostNL\Config\Provider\ProductOptions as ProductOptionsConfiguration; use TIG\PostNL\Config\Source\Options\ProductOptions as ProductOptionsFinder; +use TIG\PostNL\Service\Shipment\PepsCountries; use TIG\PostNL\Service\Wrapper\QuoteInterface; use TIG\PostNL\Service\Shipment\EpsCountries; @@ -107,22 +108,22 @@ public function get($type = '', $option = '', $address = null) if (!in_array($country, EpsCountries::ALL) && !in_array($country, ['BE', 'NL'])) { $this->getGlobalPackOption(); - return $this->response(); + return $this->response($country); } // EPS also uses delivery options in some cases. For Daytime there is no default EPS option. if ((empty($type) || $option == static::OPTION_DAYTIME) && !in_array($country, ['BE', 'NL'])) { $this->getEpsOption($address); - return $this->response(); + return $this->response($country); } if ($type == static::TYPE_PICKUP) { $this->getPakjegemakProductOption($option); - return $this->response(); + return $this->response($country); } $this->getProductCode($option, $country); - return $this->response(); + return $this->response($country); } // @codingStandardsIgnoreEnd @@ -217,13 +218,29 @@ private function getGlobalPackOption() } /** + * @param $countryId * @return array */ - private function response() + private function response($countryId) { + if ($this->productOptionsConfiguration->checkProductByFlags($this->code, 'group', 'peps_options')) { + $this->setPepsTypeByCountryId($countryId); + } + return ['code' => $this->code, 'type' => $this->type]; } + /** + * @param $country + */ + private function setPepsTypeByCountryId($country) + { + $this->type = static::SHIPMENT_TYPE_EPS; + if (in_array($country, PepsCountries::GLOBALPACK)) { + $this->type = static::SHIPMENT_TYPE_GP; + } + } + /** * @param SalesAddress|QuoteAddress|string $address * @return string From 7e17cdbb2bbc91b4313b834b17e718697ea085ce Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Tue, 22 Jan 2019 16:43:59 +0100 Subject: [PATCH 013/113] Fixed unit tests --- Service/Shipment/Packingslip/MergeWithLabels.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Service/Shipment/Packingslip/MergeWithLabels.php b/Service/Shipment/Packingslip/MergeWithLabels.php index 22e7714e0..4e0ee7c70 100644 --- a/Service/Shipment/Packingslip/MergeWithLabels.php +++ b/Service/Shipment/Packingslip/MergeWithLabels.php @@ -118,6 +118,7 @@ public function setY($packingslipYPos) * * @return string */ + // @codingStandardsIgnoreStart public function merge($shipmentId, $packingslip, $mergeFirstLabel = false, $confirm = true) { $labels = $this->getLabels->get($shipmentId, $confirm); @@ -131,14 +132,18 @@ public function merge($shipmentId, $packingslip, $mergeFirstLabel = false, $conf if ($mergeFirstLabel && $this->canMergeFirstLabel($labels[0])) { $firstLabel = array_shift($labels); - // @codingStandardsIgnoreLine $label = base64_decode($firstLabel->getLabel()); $packingslip = $this->mergeFirstLabel($label, $packingslip, $firstLabel->getType()); } + if (empty($labels)) { + return $packingslip; + } + $packingslipPdf = $this->addLabelsToPackingslip($packingslip, $labels); return $packingslipPdf; } + // @codingStandardsIgnoreEnd /** * @param ShipmentLabelInterface $firstLabel From 59d9e852cc7e4d5e123f3e5a5fc1c8f94331316d Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Thu, 24 Jan 2019 14:33:56 +0100 Subject: [PATCH 014/113] POSTNLM2-741 - Small fixes --- Service/Shipment/Customs.php | 2 +- Service/Shipment/PepsCountries.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Service/Shipment/Customs.php b/Service/Shipment/Customs.php index 52c889857..6cea7a544 100644 --- a/Service/Shipment/Customs.php +++ b/Service/Shipment/Customs.php @@ -56,7 +56,7 @@ class Customs 'Invoice' => 'false', 'Certificate' => 'false', 'License' => 'false', - 'Currency' => 'EUR', + 'Currency' => 'EUR' ]; /** diff --git a/Service/Shipment/PepsCountries.php b/Service/Shipment/PepsCountries.php index fce375989..370eb2db9 100644 --- a/Service/Shipment/PepsCountries.php +++ b/Service/Shipment/PepsCountries.php @@ -42,6 +42,7 @@ class PepsCountries * https://jira.tig.nl/browse/POSTNLM2-741 */ + // ROW const GLOBALPACK = [ 'AU', 'BR', @@ -66,6 +67,7 @@ class PepsCountries 'US' ]; + // NOT ROW const EPS = [ 'AT', 'BE', From fb8b3e875213e437259746aa4cad4d8bb3875302 Mon Sep 17 00:00:00 2001 From: Rik Jonkmans Date: Mon, 28 Jan 2019 14:32:26 +0100 Subject: [PATCH 015/113] POSTNLM2-741 - Added coding standards ignore --- Service/Shipment/PepsCountries.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Service/Shipment/PepsCountries.php b/Service/Shipment/PepsCountries.php index 370eb2db9..919c977ee 100644 --- a/Service/Shipment/PepsCountries.php +++ b/Service/Shipment/PepsCountries.php @@ -37,7 +37,10 @@ class PepsCountries * PEPS uses his own EPS and Globalpack countries. Which is different than * \TIG\PostNL\Service\Shipment\EpsCountries * - * If the country code is not in one of the arrays PEPS should / can not be used. + * @codingStandardsIgnoreStart + * @todo : If the country code is not in one of the arrays PEPS should / can not be used ? + * @todo: remove todo. + * @codingStandardsIgnoreEnd * * https://jira.tig.nl/browse/POSTNLM2-741 */ From 4ae18d2b949ddad672d9d5387ac4dc09cccd4fad Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Feb 2019 13:21:49 +0100 Subject: [PATCH 016/113] POSTNLM2-723: Fixed mistakes in group names. --- Config/Source/OptionsAbstract.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Config/Source/OptionsAbstract.php b/Config/Source/OptionsAbstract.php index 6ddd7350a..de66e04d2 100644 --- a/Config/Source/OptionsAbstract.php +++ b/Config/Source/OptionsAbstract.php @@ -648,7 +648,7 @@ abstract class OptionsAbstract 'id_check_pakjegemak_options' => 'ID Check Post Office options', 'cargo_options' => 'Cargo options', 'eps_package_options' => 'Package options', - 'peps_products' => 'Priority EPS' + 'peps_options' => 'Priority EPS' ]; protected $groupToLabel = [ @@ -662,7 +662,7 @@ abstract class OptionsAbstract 'id_check_pakjegemak_options' => 'ID Check Post Office', 'cargo_options' => 'Cargo', 'eps_package_options' => 'Package', - 'peps_products' => 'Priority (EPS / Globalpack)' + 'peps_options' => 'Priority (EPS / Globalpack)' ]; protected $typeToComment = [ From 0457f4a9e105169b6a0ffc07e44fb7013816e5f2 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 12 Feb 2019 14:26:29 +0100 Subject: [PATCH 017/113] Fixed 'filterd' typo --- Config/Source/OptionsAbstract.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Config/Source/OptionsAbstract.php b/Config/Source/OptionsAbstract.php index de66e04d2..1d50f80fe 100644 --- a/Config/Source/OptionsAbstract.php +++ b/Config/Source/OptionsAbstract.php @@ -680,7 +680,7 @@ abstract class OptionsAbstract /** * Property for filterd product options matched by account type and flags. */ - private $filterdOptions; + private $filteredOptions; /** * Group options by group types @@ -703,7 +703,7 @@ public function get() public function getProductoptions($flags = false) { if (false !== $flags && is_array($flags)) { - $this->setFilterdOptions($flags); + $this->setFilteredOptions($flags); } return $this->getOptionArrayUsableForConfiguration(); @@ -714,9 +714,9 @@ public function getProductoptions($flags = false) * * @codingStandardsIgnoreLine */ - public function setFilterdOptions($flags) + public function setFilteredOptions($flags) { - $this->filterdOptions = []; + $this->filteredOptions = []; // Filter availableOptions on flags foreach ($this->availableOptions as $key => $option) { @@ -743,7 +743,7 @@ public function setOptionsByFlagFilters($flags, $option, $productCode) }, \Zend\Stdlib\ArrayUtils::ARRAY_FILTER_USE_BOTH); if (count($filterFlags) == count($flags)) { - $this->filterdOptions[$productCode] = $this->availableOptions[$productCode]; + $this->filteredOptions[$productCode] = $this->availableOptions[$productCode]; } } @@ -763,7 +763,7 @@ public function setOptionsByMultipleFlagFilters($flags, $option, $productCode) }, \Zend\Stdlib\ArrayUtils::ARRAY_FILTER_USE_BOTH); if (count($filterFlags) == count($flags)) { - $this->filterdOptions[$productCode] = $this->availableOptions[$productCode]; + $this->filteredOptions[$productCode] = $this->availableOptions[$productCode]; } } } @@ -773,13 +773,13 @@ public function setOptionsByMultipleFlagFilters($flags, $option, $productCode) */ public function getOptionArrayUsableForConfiguration() { - if (count($this->filterdOptions) == 0) { + if (count($this->filteredOptions) == 0) { // @codingStandardsIgnoreLine return [['value' => 0, 'label' => __('There are no available options')]]; } $options = []; - foreach ($this->filterdOptions as $key => $option) { + foreach ($this->filteredOptions as $key => $option) { // @codingStandardsIgnoreLine $options[] = ['value' => $option['value'], 'label' => __($option['label'])]; } From 55eda31f1dc67512bc236be5e2b4ff38757b6af5 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 12 Feb 2019 15:05:35 +0100 Subject: [PATCH 018/113] POSTNLM2-741: Refactored code and added PEPS options. --- Config/Source/Options/DefaultOptions.php | 106 +++++++++++++++++------ 1 file changed, 78 insertions(+), 28 deletions(-) diff --git a/Config/Source/Options/DefaultOptions.php b/Config/Source/Options/DefaultOptions.php index 787fa8045..3506620b6 100644 --- a/Config/Source/Options/DefaultOptions.php +++ b/Config/Source/Options/DefaultOptions.php @@ -34,6 +34,11 @@ use Magento\Framework\Option\ArrayInterface; use TIG\PostNL\Config\Provider\ShippingOptions; +/** + * @todo we need to move the getOption-methods to the ProductOptions class without + * creating a circular dependency. For now we allow CS to ignore this file. + */ +// @codingStandardsIgnoreFile class DefaultOptions implements ArrayInterface { /** @@ -87,60 +92,105 @@ public function toOptionArray() */ public function getBeProducts() { - $epsBusinessOptions = []; - if ($this->shippingOptions->canUseEpsBusinessProducts()) { - $epsBusinessOptions = $this->productOptions->getProductoptions( - ['isEvening' => false, 'group' => 'eps_package_options'] - ); - } + $beProducts = [ + $this->getEuOptions(), + $this->getEpsBusinessOptions(), + $this->getPepsOptions(), + $this->getCargoOptions() + ]; + + return call_user_func_array("array_merge", $beProducts); + } - $cargoProducts = []; - if ($this->shippingOptions->canUseCargoProducts()) { - $cargoProducts = $this->productOptions->getProductoptions( - ['countryLimitation' => 'BE', 'group' => 'cargo_options'] - ); - } + /** + * @return array + */ + public function getEpsProducts() + { + $epsProducts = [ + $this->getEpsOptions(), + $this->getPepsOptions(), + $this->getEpsBusinessOptions() + ]; - $epsBusinessOptions = array_merge($epsBusinessOptions, $cargoProducts); - return array_merge($this->productOptions->getProductoptions(['group' => 'eu_options']), $epsBusinessOptions); + return call_user_func_array("array_merge", $epsProducts); } /** * @return array */ - public function getEpsProducts() + public function getGlobalProducts() + { + $globalOptions = [ + $this->productOptions->getProductoptions(['group' => 'global_options']), + $this->getPepsOptions(), + ]; + + return call_user_func_array("array_merge" ,$globalOptions); + } + + /** + * @return array + */ + public function getEuOptions() + { + $euOptions = $this->productOptions->getProductoptions(['group' => 'eu_options']) ?: []; + + return $euOptions; + } + + /** + * @return array + */ + public function getEpsOptions() { $epsOptions = $this->productOptions->getProductoptions( ['isEvening' => false, 'countryLimitation' => false, 'group' => 'eu_options'] - ); + ) ?: []; + return $epsOptions; + } + /** + * @return array + */ + public function getPepsOptions() + { + $pepsOptions = []; if ($this->shippingOptions->canUsePepsProducts()) { $pepsOptions = $this->productOptions->getProductoptions(['group' => 'peps_options']); - $epsOptions = array_merge($epsOptions, $pepsOptions); } + return $pepsOptions; + } + /** + * @return array + */ + public function getEpsBusinessOptions() + { + $epsBusinessOptions = []; if ($this->shippingOptions->canUseEpsBusinessProducts()) { $epsBusinessOptions = $this->productOptions->getProductoptions( - ['isEvening' => false, 'countryLimitation' => false, 'group' => 'eps_package_options'] + [ + 'isEvening' => false, + 'group' => 'eps_package_options' + ] ); - $epsOptions = array_merge($epsOptions, $epsBusinessOptions); } - - return $epsOptions; + return $epsBusinessOptions; } /** * @return array */ - public function getGlobalProducts() + public function getCargoOptions() { - $globalOptions = $this->productOptions->getProductoptions(['group' => 'global_options']); - if ($this->shippingOptions->canUsePepsProducts()) { - $pepsOptions = $this->productOptions->getProductoptions(['group' => 'peps_options']); - $globalOptions = array_merge($globalOptions, $pepsOptions); + $cargoProducts = []; + if ($this->shippingOptions->canUseCargoProducts()) { + $cargoProducts = $this->productOptions->getProductoptions( + ['countryLimitation' => 'BE', 'group' => 'cargo_options'] + ); } - - return $globalOptions; + return $cargoProducts; } /** From 64183815efc29fd66a468b713a16451d88354c67 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 12 Feb 2019 15:06:58 +0100 Subject: [PATCH 019/113] POSTNLM2-741: Small typo. --- Config/Source/Options/DefaultOptions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config/Source/Options/DefaultOptions.php b/Config/Source/Options/DefaultOptions.php index 3506620b6..9a8f927b3 100644 --- a/Config/Source/Options/DefaultOptions.php +++ b/Config/Source/Options/DefaultOptions.php @@ -126,7 +126,7 @@ public function getGlobalProducts() $this->getPepsOptions(), ]; - return call_user_func_array("array_merge" ,$globalOptions); + return call_user_func_array("array_merge", $globalOptions); } /** From f95cf856bb0c869b0062d4913647d6aa25e2c53d Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 12 Feb 2019 15:35:36 +0100 Subject: [PATCH 020/113] POSTNLM2-618: Separated Options from Products getters. --- Config/Source/Options/DefaultOptions.php | 95 +++++------------------- Config/Source/Options/ProductOptions.php | 58 +++++++++++++++ 2 files changed, 78 insertions(+), 75 deletions(-) diff --git a/Config/Source/Options/DefaultOptions.php b/Config/Source/Options/DefaultOptions.php index 9a8f927b3..3b077632f 100644 --- a/Config/Source/Options/DefaultOptions.php +++ b/Config/Source/Options/DefaultOptions.php @@ -92,11 +92,15 @@ public function toOptionArray() */ public function getBeProducts() { + $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPepsOptions() : []; + $epsBusinessOptions = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; + $cargoOptions = $this->shippingOptions->canUseCargoProducts() ? $this->productOptions->getCargoOptions() : []; + $beProducts = [ - $this->getEuOptions(), - $this->getEpsBusinessOptions(), - $this->getPepsOptions(), - $this->getCargoOptions() + $this->productOptions->getEuOptions(), + $pepsOptions, + $epsBusinessOptions, + $cargoOptions ]; return call_user_func_array("array_merge", $beProducts); @@ -107,10 +111,13 @@ public function getBeProducts() */ public function getEpsProducts() { + $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPepsOptions() : []; + $epsBusinessOptions = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; + $epsProducts = [ - $this->getEpsOptions(), - $this->getPepsOptions(), - $this->getEpsBusinessOptions() + $this->productOptions->getEpsOptions(), + $pepsOptions, + $epsBusinessOptions ]; return call_user_func_array("array_merge", $epsProducts); @@ -121,76 +128,14 @@ public function getEpsProducts() */ public function getGlobalProducts() { - $globalOptions = [ - $this->productOptions->getProductoptions(['group' => 'global_options']), - $this->getPepsOptions(), - ]; - - return call_user_func_array("array_merge", $globalOptions); - } - - /** - * @return array - */ - public function getEuOptions() - { - $euOptions = $this->productOptions->getProductoptions(['group' => 'eu_options']) ?: []; + $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPepsOptions() : []; - return $euOptions; - } - - /** - * @return array - */ - public function getEpsOptions() - { - $epsOptions = $this->productOptions->getProductoptions( - ['isEvening' => false, 'countryLimitation' => false, 'group' => 'eu_options'] - ) ?: []; - return $epsOptions; - } - - /** - * @return array - */ - public function getPepsOptions() - { - $pepsOptions = []; - if ($this->shippingOptions->canUsePepsProducts()) { - $pepsOptions = $this->productOptions->getProductoptions(['group' => 'peps_options']); - } - return $pepsOptions; - } - - /** - * @return array - */ - public function getEpsBusinessOptions() - { - $epsBusinessOptions = []; - if ($this->shippingOptions->canUseEpsBusinessProducts()) { - $epsBusinessOptions = $this->productOptions->getProductoptions( - [ - 'isEvening' => false, - 'group' => 'eps_package_options' - ] - ); - } - return $epsBusinessOptions; - } + $globalProducts = [ + $this->productOptions->getGlobalPackOptions(), + $pepsOptions, + ]; - /** - * @return array - */ - public function getCargoOptions() - { - $cargoProducts = []; - if ($this->shippingOptions->canUseCargoProducts()) { - $cargoProducts = $this->productOptions->getProductoptions( - ['countryLimitation' => 'BE', 'group' => 'cargo_options'] - ); - } - return $cargoProducts; + return call_user_func_array("array_merge", $globalProducts); } /** diff --git a/Config/Source/Options/ProductOptions.php b/Config/Source/Options/ProductOptions.php index 80ecf79c6..59696c8c9 100644 --- a/Config/Source/Options/ProductOptions.php +++ b/Config/Source/Options/ProductOptions.php @@ -163,6 +163,52 @@ public function getEpsProductOptions($address = false) return $this->getProductoptions(['group' => 'eu_options']); } + /** + * @return array + */ + public function getEuOptions() + { + $euOptions = $this->getProductoptions(['group' => 'eu_options']); + + return $euOptions; + } + + /** + * @return array + */ + public function getEpsOptions() + { + $epsOptions = $this->getProductoptions( + ['isEvening' => false, 'countryLimitation' => false, 'group' => 'eu_options'] + ); + return $epsOptions; + } + + /** + * @return array + */ + public function getPepsOptions() + { + $pepsOptions = $this->getProductoptions(['group' => 'peps_options']); + + return $pepsOptions; + } + + /** + * @return array + */ + public function getEpsBusinessOptions() + { + $epsBusinessOptions = $this->getProductoptions( + [ + 'isEvening' => false, + 'group' => 'eps_package_options' + ] + ); + + return $epsBusinessOptions; + } + /** * @return array */ @@ -179,6 +225,18 @@ public function getExtraAtHomeOptions() return $this->getProductoptions(['group' => 'extra_at_home_options']); } + /** + * @return array + */ + public function getCargoOptions() + { + $cargoProducts = $this->getProductoptions( + ['countryLimitation' => 'BE', 'group' => 'cargo_options'] + ); + + return $cargoProducts; + } + /** * @param $code * From 395601f15f1dd53c0012865e270306d688b14c05 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 28 Feb 2019 09:51:12 +0100 Subject: [PATCH 021/113] POSTNLM2-741: Fix bugs for (Priority) EPS and GlobalPack without affecting current flow. --- Config/Source/Options/ProductOptions.php | 44 +++- Config/Source/OptionsAbstract.php | 10 +- Service/Order/ProductCodeAndType.php | 265 -------------------- Service/Order/ProductInfo.php | 295 +++++++++++++++++++++++ Service/Shipment/PepsCountries.php | 7 +- 5 files changed, 334 insertions(+), 287 deletions(-) delete mode 100644 Service/Order/ProductCodeAndType.php create mode 100644 Service/Order/ProductInfo.php diff --git a/Config/Source/Options/ProductOptions.php b/Config/Source/Options/ProductOptions.php index 529a5ee09..62f300bcf 100644 --- a/Config/Source/Options/ProductOptions.php +++ b/Config/Source/Options/ProductOptions.php @@ -104,7 +104,7 @@ public function toOptionArray() */ public function getIsSundayOptions() { - return $this->getProductoptions(['isSunday' => true]); + return $this->getProductOptions(['isSunday' => true]); } /** @@ -116,7 +116,7 @@ public function getPakjeGemakOptions() $flags = []; $flags['groups'][] = ['group' => 'pakjegemak_options']; $flags['groups'][] = ['group' => 'id_check_pakjegemak_options']; - return $this->getProductoptions($flags); + return $this->getProductOptions($flags); } /** @@ -125,7 +125,7 @@ public function getPakjeGemakOptions() */ public function getPakjeGemakEarlyDeliveryOptions() { - return $this->getProductoptions(['pge' => true]); + return $this->getProductOptions(['pge' => true]); } /** @@ -139,7 +139,7 @@ public function getDefaultOptions() $flags['groups'][] = ['group' => 'id_check_options']; $flags['groups'][] = ['group' => 'cargo_options']; - return $this->getProductoptions($flags); + return $this->getProductOptions($flags); } /** @@ -147,7 +147,7 @@ public function getDefaultOptions() */ public function getExtraCoverProductOptions() { - return $this->getProductoptions(['isExtraCover' => true]); + return $this->getProductOptions(['isExtraCover' => true]); } /** @@ -160,7 +160,7 @@ public function getEpsProductOptions($address = false) if ($address && $address->getCountryId() === 'ES' && $this->canaryConverter->isCanaryIsland($address)) { return $this->getGlobalPackOptions(); } - return $this->getProductoptions(['isEvening' => false, 'countryLimitation' => false, 'group' => 'eu_options']); + return $this->getProductOptions(['isEvening' => false, 'countryLimitation' => false, 'group' => 'eu_options']); } /** @@ -168,7 +168,7 @@ public function getEpsProductOptions($address = false) */ public function getEuOptions() { - $euOptions = $this->getProductoptions(['group' => 'eu_options']); + $euOptions = $this->getProductOptions(['group' => 'eu_options']); return $euOptions; } @@ -178,7 +178,7 @@ public function getEuOptions() */ public function getEpsOptions() { - $epsOptions = $this->getProductoptions( + $epsOptions = $this->getProductOptions( ['isEvening' => false, 'countryLimitation' => false, 'group' => 'eu_options'] ); return $epsOptions; @@ -189,7 +189,7 @@ public function getEpsOptions() */ public function getPepsOptions() { - $pepsOptions = $this->getProductoptions(['group' => 'peps_options']); + $pepsOptions = $this->getProductOptions(['group' => 'peps_options']); return $pepsOptions; } @@ -199,7 +199,7 @@ public function getPepsOptions() */ public function getEpsBusinessOptions() { - $epsBusinessOptions = $this->getProductoptions( + $epsBusinessOptions = $this->getProductOptions( [ 'isEvening' => false, 'group' => 'eps_package_options' @@ -214,7 +214,7 @@ public function getEpsBusinessOptions() */ public function getGlobalPackOptions() { - return $this->getProductoptions(['group' => 'global_options']); + return $this->getProductOptions(['group' => 'global_options']); } /** @@ -222,7 +222,25 @@ public function getGlobalPackOptions() */ public function getExtraAtHomeOptions() { - return $this->getProductoptions(['group' => 'extra_at_home_options']); + return $this->getProductOptions(['group' => 'extra_at_home_options']); + } + + /** + * @return array + */ + public function getDefaultGPOption() + { + $productOptions = $this->getProductOptions(['isDefault' => 1, 'group' => 'global_options']); + return array_shift($productOptions); + } + + /** + * @return array + */ + public function getDefaultEUOption() + { + $productOptions = $this->getProductOptions(['isDefault' => 1, 'group' => 'eu_options']); + return array_shift($productOptions); } /** @@ -230,7 +248,7 @@ public function getExtraAtHomeOptions() */ public function getCargoOptions() { - $cargoProducts = $this->getProductoptions( + $cargoProducts = $this->getProductOptions( ['countryLimitation' => 'BE', 'group' => 'cargo_options'] ); diff --git a/Config/Source/OptionsAbstract.php b/Config/Source/OptionsAbstract.php index 1d50f80fe..cb1920a97 100644 --- a/Config/Source/OptionsAbstract.php +++ b/Config/Source/OptionsAbstract.php @@ -188,6 +188,7 @@ abstract class OptionsAbstract '4952' => [ 'value' => '4952', 'label' => 'EU Pack Special Consumer', + 'isDefault' => 1, 'isEvening' => false, 'isExtraCover' => false, 'isSunday' => false, @@ -239,6 +240,7 @@ abstract class OptionsAbstract '4945' => [ 'value' => '4945', 'label' => 'GlobalPack', + 'isDefault' => 1, 'isEvening' => false, 'isExtraCover' => false, 'isSunday' => false, @@ -648,7 +650,7 @@ abstract class OptionsAbstract 'id_check_pakjegemak_options' => 'ID Check Post Office options', 'cargo_options' => 'Cargo options', 'eps_package_options' => 'Package options', - 'peps_options' => 'Priority EPS' + 'peps_options' => 'Priority EPS' ]; protected $groupToLabel = [ @@ -662,7 +664,7 @@ abstract class OptionsAbstract 'id_check_pakjegemak_options' => 'ID Check Post Office', 'cargo_options' => 'Cargo', 'eps_package_options' => 'Package', - 'peps_options' => 'Priority (EPS / Globalpack)' + 'peps_options' => 'Priority (EPS / Globalpack)' ]; protected $typeToComment = [ @@ -678,7 +680,7 @@ abstract class OptionsAbstract ]; /** - * Property for filterd product options matched by account type and flags. + * Property for filtered product options matched by account type and flags. */ private $filteredOptions; @@ -700,7 +702,7 @@ public function get() * * @return array $availableOptions */ - public function getProductoptions($flags = false) + public function getProductOptions($flags = false) { if (false !== $flags && is_array($flags)) { $this->setFilteredOptions($flags); diff --git a/Service/Order/ProductCodeAndType.php b/Service/Order/ProductCodeAndType.php deleted file mode 100644 index 1e53413c5..000000000 --- a/Service/Order/ProductCodeAndType.php +++ /dev/null @@ -1,265 +0,0 @@ -productOptionsConfiguration = $productOptionsConfiguration; - $this->productOptionsFinder = $productOptionsFinder; - $this->quote = $quote; - } - - /** - * This function translates the chosen option to the correct product code for the shipment. - * - * @param string $type - * @param string $option - * @param SalesAddress|QuoteAddress $address - * - * @return array - */ - // @codingStandardsIgnoreStart - public function get($type = '', $option = '', $address = null) - { - $country = $this->getCountryCode($address); - $type = strtolower($type); - $option = strtolower($option); - - if (!in_array($country, EpsCountries::ALL) && !in_array($country, ['BE', 'NL'])) { - $this->getGlobalPackOption(); - return $this->response($country); - } - - // EPS also uses delivery options in some cases. For Daytime there is no default EPS option. - if ((empty($type) || $option == static::OPTION_DAYTIME) && !in_array($country, ['BE', 'NL'])) { - $this->getEpsOption($address); - return $this->response($country); - } - - if ($type == static::TYPE_PICKUP) { - $this->getPakjegemakProductOption($option); - return $this->response($country); - } - - $this->getProductCode($option, $country); - return $this->response($country); - } - // @codingStandardsIgnoreEnd - - /** - * Get the product code for the delivery options. - * - * @param string $option - * @param string $country - */ - private function getProductCode($option, $country) - { - switch ($option) { - case static::OPTION_EVENING: - $this->code = $this->productOptionsConfiguration->getDefaultEveningProductOption($country); - $this->type = static::SHIPMENT_TYPE_EVENING; - return; - case static::OPTION_SUNDAY: - $this->code = $this->productOptionsConfiguration->getDefaultSundayProductOption(); - $this->type = static::SHIPMENT_TYPE_SUNDAY; - return; - case static::OPTION_EXTRAATHOME: - $this->code = $this->productOptionsConfiguration->getDefaultExtraAtHomeProductOption(); - $this->type = static::SHIPMENT_TYPE_EXTRAATHOME; - return; - } - - $this->getDefaultProductOption($country); - } - - /** - * @param $country - */ - private function getDefaultProductOption($country) - { - $this->code = $this->productOptionsConfiguration->getDefaultProductOption(); - if ($country == 'BE') { - $this->code = $this->productOptionsConfiguration->getDefaultBeProductOption(); - } - - $this->type = static::SHIPMENT_TYPE_DAYTIME; - - /** @var Quote $magentoQuote */ - $magentoQuote = $this->quote->getQuote(); - $quoteTotal = $magentoQuote->getBaseGrandTotal(); - $alternativeActive = $this->productOptionsConfiguration->getUseAlternativeDefault(); - $alternativeMinAmount = $this->productOptionsConfiguration->getAlternativeDefaultMinAmount(); - - if ($alternativeActive && $quoteTotal >= $alternativeMinAmount) { - $this->code = $this->productOptionsConfiguration->getAlternativeDefaultProductOption(); - } - } - - /** - * @param string $option - */ - private function getPakjegemakProductOption($option) - { - if ($option == static::OPTION_PGE) { - $this->code = $this->productOptionsConfiguration->getDefaultPakjeGemakEarlyProductOption(); - $this->type = static::SHIPMENT_TYPE_PGE; - return; - } - - $this->code = $this->productOptionsConfiguration->getDefaultPakjeGemakProductOption(); - $this->type = static::SHIPMENT_TYPE_PG; - } - - /** - * Parse EPS options. - * @param $address - */ - private function getEpsOption($address) - { - $options = $this->productOptionsFinder->getEpsProductOptions($address); - $firstOption = array_shift($options); - - $this->code = $this->productOptionsConfiguration->getDefaultEpsProductOption(); - $this->type = static::SHIPMENT_TYPE_EPS; - // Force type Global Pack (mainly used for Canary Islands) - if (in_array('4945', $firstOption)) { - $this->getGlobalPackOption(); - } - } - - /** - * Parse Globalpack options. - */ - private function getGlobalPackOption() - { - $this->code = $this->productOptionsConfiguration->getDefaultGlobalpackOption(); - $this->type = static::SHIPMENT_TYPE_GP; - } - - /** - * @param $countryId - * @return array - */ - private function response($countryId) - { - if ($this->productOptionsConfiguration->checkProductByFlags($this->code, 'group', 'peps_options')) { - $this->setPepsTypeByCountryId($countryId); - } - - return ['code' => $this->code, 'type' => $this->type]; - } - - /** - * @param $country - */ - private function setPepsTypeByCountryId($country) - { - $this->type = static::SHIPMENT_TYPE_EPS; - if (in_array($country, PepsCountries::GLOBALPACK)) { - $this->type = static::SHIPMENT_TYPE_GP; - } - } - - /** - * @param SalesAddress|QuoteAddress|string $address - * @return string - */ - private function getCountryCode($address) - { - if ($address && is_object($address)) { - return $address->getCountryId(); - } - - /** - * \TIG\PostNL\Helper\DeliveryOptions\OrderParams::formatParamData - * Request is done with country code only. - */ - if (is_string($address)) { - return $address; - } - - $address = $this->quote->getShippingAddress(); - return $address->getCountryId(); - } -} diff --git a/Service/Order/ProductInfo.php b/Service/Order/ProductInfo.php new file mode 100644 index 000000000..53f1e7bed --- /dev/null +++ b/Service/Order/ProductInfo.php @@ -0,0 +1,295 @@ +productOptionsConfiguration = $productOptionsConfiguration; + $this->productOptionsFinder = $productOptionsFinder; + $this->quote = $quote; + } + + /** + * This function translates the chosen option to the correct product code for the shipment. + * + * @param string $type + * @param string $option + * @param SalesAddress|QuoteAddress $address + * + * @return array + */ + public function get($type = '', $option = '', $address = null) { + $country = $this->getCountryCode($address); + $type = strtolower($type); + $option = strtolower($option); + + if (!in_array($country, EpsCountries::ALL) + && !in_array($country, ['BE', 'NL'])) { + $this->setGlobalPackOption($country); + + return $this->getInfo(); + } + + // EPS also uses delivery options in some cases. For Daytime there is no default EPS option. + if ((empty($type) || $option == static::OPTION_DAYTIME) + && !in_array($country, ['BE', 'NL'])) { + $this->setEpsOption($address, $country); + + return $this->getInfo(); + } + + if ($type == static::TYPE_PICKUP) { + $this->setPakjegemakProductOption($option); + + return $this->getInfo(); + } + + $this->setProductCode($option, $country); + + return $this->getInfo(); + } + + /** + * @param SalesAddress|QuoteAddress|string $address + * + * @return string + */ + private function getCountryCode($address) { + if ($address && is_object($address)) { + return $address->getCountryId(); + } + + /** + * \TIG\PostNL\Helper\DeliveryOptions\OrderParams::formatParamData + * Request is done with country code only. + */ + if (is_string($address)) { + return $address; + } + + $address = $this->quote->getShippingAddress(); + + return $address->getCountryId(); + } + + /** + * @param null $country + */ + private function setGlobalPackOption($country = null) { + $this->type = static::SHIPMENT_TYPE_GP; + $this->code = $this->productOptionsConfiguration->getDefaultGlobalpackOption(); + + if (in_array($country, PepsCountries::GLOBALPACK) + && $this->isPriorityProduct($this->code) + ) { + return; + } + + $this->code = $this->productOptionsFinder->getDefaultGPOption()['value']; + } + + /** + * @param $address + * @param $country + */ + private function setEpsOption($address, $country) { + $this->type = static::SHIPMENT_TYPE_EPS; + + // Force type Global Pack (mainly used for Canary Islands) + $options = $this->productOptionsFinder->getEpsProductOptions($address); + $firstOption = array_shift($options); + if (in_array('4945', $firstOption)) { + $this->setGlobalPackOption(); + + return; + } + + $this->code = $this->productOptionsConfiguration->getDefaultEpsProductOption(); + if (in_array($country, PepsCountries::EPS) + && $this->isPriorityProduct($this->code) + ) { + return; + } + + $this->code = $this->productOptionsFinder->getDefaultEUOption()['value']; + } + + /** + * Check whether current product code is a Priority (GlobalPack|EPS) Product + * + * @param $code + * + * @return bool|null + */ + private function isPriorityProduct($code) { + return $this->productOptionsConfiguration->checkProductByFlags($code, 'group', 'peps_options'); + } + + /** + * @param string $option + */ + private function setPakjegemakProductOption($option) { + if ($option == static::OPTION_PGE) { + $this->code = $this->productOptionsConfiguration->getDefaultPakjeGemakEarlyProductOption(); + $this->type = static::SHIPMENT_TYPE_PGE; + + return; + } + + $this->code = $this->productOptionsConfiguration->getDefaultPakjeGemakProductOption(); + $this->type = static::SHIPMENT_TYPE_PG; + } + + /** + * Set the product code for the delivery options. + * + * @param string $option + * @param string $country + */ + private function setProductCode($option, $country) { + switch ($option) { + case static::OPTION_EVENING: + $this->code = $this->productOptionsConfiguration->getDefaultEveningProductOption($country); + $this->type = static::SHIPMENT_TYPE_EVENING; + + return; + case static::OPTION_SUNDAY: + $this->code = $this->productOptionsConfiguration->getDefaultSundayProductOption(); + $this->type = static::SHIPMENT_TYPE_SUNDAY; + + return; + case static::OPTION_EXTRAATHOME: + $this->code = $this->productOptionsConfiguration->getDefaultExtraAtHomeProductOption(); + $this->type = static::SHIPMENT_TYPE_EXTRAATHOME; + + return; + } + + $this->setDefaultProductOption($country); + } + + /** + * @param $country + */ + private function setDefaultProductOption($country) { + $this->code = $this->productOptionsConfiguration->getDefaultProductOption(); + if ($country == 'BE') { + $this->code = $this->productOptionsConfiguration->getDefaultBeProductOption(); + } + + $this->type = static::SHIPMENT_TYPE_DAYTIME; + + /** @var Quote $magentoQuote */ + $magentoQuote = $this->quote->getQuote(); + $quoteTotal = $magentoQuote->getBaseGrandTotal(); + $alternativeActive = $this->productOptionsConfiguration->getUseAlternativeDefault(); + $alternativeMinAmount = $this->productOptionsConfiguration->getAlternativeDefaultMinAmount(); + + if ($alternativeActive && $quoteTotal >= $alternativeMinAmount) { + $this->code = $this->productOptionsConfiguration->getAlternativeDefaultProductOption(); + } + } + + /** + * @return array + */ + private function getInfo() { + return ['code' => $this->code, 'type' => $this->type]; + } +} diff --git a/Service/Shipment/PepsCountries.php b/Service/Shipment/PepsCountries.php index 919c977ee..c05977af3 100644 --- a/Service/Shipment/PepsCountries.php +++ b/Service/Shipment/PepsCountries.php @@ -36,11 +36,8 @@ class PepsCountries /** * PEPS uses his own EPS and Globalpack countries. Which is different than * \TIG\PostNL\Service\Shipment\EpsCountries - * - * @codingStandardsIgnoreStart - * @todo : If the country code is not in one of the arrays PEPS should / can not be used ? - * @todo: remove todo. - * @codingStandardsIgnoreEnd + * If country does not exist in both arrays a fallback to Regular Globalpack + * is provided. * * https://jira.tig.nl/browse/POSTNLM2-741 */ From a736d14df7fd1547a240db4f383e94d9765b874b Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 28 Feb 2019 09:52:16 +0100 Subject: [PATCH 022/113] POSTNLM2-741: Fixed bug where Default Worldwide Delivery would not show when Worldwide Shipping as enabled. --- etc/adminhtml/system/globalpack.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etc/adminhtml/system/globalpack.xml b/etc/adminhtml/system/globalpack.xml index fcfbbf05f..5a8b30bb7 100644 --- a/etc/adminhtml/system/globalpack.xml +++ b/etc/adminhtml/system/globalpack.xml @@ -40,6 +40,7 @@ 1 \TIG\PostNL\Block\Adminhtml\Config\Globalpack\UsingGlobalpack + Worldwide shipping uses the PostNL GlobalPack product. @@ -53,7 +54,7 @@ TIG\PostNL\Config\Source\Options\DefaultOptions::getGlobalProducts tig_postnl/globalpack/default_gp_option - 1 + 1 From d4152e90cc2e3fc2357f8f5cfbc91ff058d10fa1 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 28 Feb 2019 09:56:22 +0100 Subject: [PATCH 023/113] Fixed several typo's. Minor re-factoring of illogical class and method names. --- .../IsShippingOptionsActive.php | 4 +- Config/Source/Options/DefaultOptions.php | 6 +-- Controller/Adminhtml/PdfDownload.php | 4 +- Helper/DeliveryOptions/OrderParams.php | 20 ++++---- .../SalesOrderSaveAfter/CreatePostNLOrder.php | 30 +++++------ .../SetDefaultData.php | 50 ++++++++++--------- Service/Options/ItemsToOption.php | 4 +- Service/Shipment/Label/Generate.php | 4 +- .../Shipment/Packingslip/MergeWithLabels.php | 6 +-- .../Observer/SetDefaultDataTest.php | 24 ++++----- .../Service/Options/ItemsToOptionTest.php | 4 +- .../IsShippingOptionsActiveTest.php | 4 +- .../DeliveryOptions/OrderParamsTest.php | 10 ++-- .../Service/Carrier/ParcelTypeFinderTest.php | 6 +-- Test/Unit/Service/Order/ProductCodeTest.php | 4 +- .../Quote/CheckIfQuoteHasOptionTest.php | 6 +-- 16 files changed, 94 insertions(+), 92 deletions(-) diff --git a/Config/CheckoutConfiguration/IsShippingOptionsActive.php b/Config/CheckoutConfiguration/IsShippingOptionsActive.php index e15126e49..70af716d2 100644 --- a/Config/CheckoutConfiguration/IsShippingOptionsActive.php +++ b/Config/CheckoutConfiguration/IsShippingOptionsActive.php @@ -37,7 +37,7 @@ use TIG\PostNL\Service\Quote\CheckIfQuoteItemsAreInStock; use TIG\PostNL\Service\Quote\CheckIfQuoteItemsCanBackorder; use \TIG\PostNL\Service\Quote\CheckIfQuoteHasOption; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; class IsShippingOptionsActive implements CheckoutConfigurationInterface { @@ -98,7 +98,7 @@ public function getValue() return false; } - if ($this->quoteHasOption->get(ProductCodeAndType::OPTION_EXTRAATHOME)) { + if ($this->quoteHasOption->get(ProductInfo::OPTION_EXTRAATHOME)) { return false; } diff --git a/Config/Source/Options/DefaultOptions.php b/Config/Source/Options/DefaultOptions.php index 3b077632f..3e2bb590a 100644 --- a/Config/Source/Options/DefaultOptions.php +++ b/Config/Source/Options/DefaultOptions.php @@ -84,7 +84,7 @@ public function toOptionArray() $flags['groups'][] = ['group' => 'eps_package_options']; } - return $this->productOptions->getProductoptions($flags); + return $this->productOptions->getProductOptions($flags); } /** @@ -161,12 +161,12 @@ public function getEveningOptionsBE() */ public function getEveningOptions($country = 'NL') { - $options = $this->productOptions->getProductoptions(['isEvening' => true, 'countryLimitation' => $country]); + $options = $this->productOptions->getProductOptions(['isEvening' => true, 'countryLimitation' => $country]); if ($this->shippingOptions->isIDCheckActive()) { return $options; } - $idOptions = $this->productOptions->getProductoptions( + $idOptions = $this->productOptions->getProductOptions( ['group' => 'id_check_options', 'countryLimitation' => $country] ); diff --git a/Controller/Adminhtml/PdfDownload.php b/Controller/Adminhtml/PdfDownload.php index f836d478a..d453068fc 100644 --- a/Controller/Adminhtml/PdfDownload.php +++ b/Controller/Adminhtml/PdfDownload.php @@ -40,7 +40,7 @@ use TIG\PostNL\Service\Shipment\Label\Generate as LabelGenerate; use TIG\PostNL\Service\Shipment\Packingslip\Generate as PackingslipGenerate; use TIG\PostNL\Service\Shipment\ShipmentService as Shipment; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; // @codingStandardsIgnoreFile class PdfDownload @@ -155,7 +155,7 @@ private function filterLabel($labels) { return array_filter($labels, function ($label) { /** @var ShipmentLabelInterface $label */ - if (strtoupper($label->getType()) == ProductCodeAndType::SHIPMENT_TYPE_GP) { + if (strtoupper($label->getType()) == ProductInfo::SHIPMENT_TYPE_GP) { $this->filteredLabels[] = $label->getParentId(); return false; } diff --git a/Helper/DeliveryOptions/OrderParams.php b/Helper/DeliveryOptions/OrderParams.php index 7a323acb8..49dfec644 100644 --- a/Helper/DeliveryOptions/OrderParams.php +++ b/Helper/DeliveryOptions/OrderParams.php @@ -33,7 +33,7 @@ use TIG\PostNL\Exception as PostnlException; use TIG\PostNL\Service\Order\FeeCalculator; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Service\Shipment\ProductOptions; class OrderParams @@ -78,9 +78,9 @@ class OrderParams private $feeCalculator; /** - * @var ProductCodeAndType + * @var ProductInfo */ - private $productCodeAndType; + private $productInfo; /** * @var ProductOptions @@ -88,18 +88,18 @@ class OrderParams private $productOptions; /** - * @param FeeCalculator $feeCalculator - * @param ProductCodeAndType $productCodeAndType + * @param FeeCalculator $feeCalculator + * @param ProductInfo $productInfo * @param ProductOptions $productOptions */ public function __construct( FeeCalculator $feeCalculator, - ProductCodeAndType $productCodeAndType, + ProductInfo $productInfo, ProductOptions $productOptions ) { - $this->feeCalculator = $feeCalculator; - $this->productCodeAndType = $productCodeAndType; - $this->productOptions = $productOptions; + $this->feeCalculator = $feeCalculator; + $this->productInfo = $productInfo; + $this->productOptions = $productOptions; } /** @@ -170,7 +170,7 @@ private function setRequiredList($type) */ private function formatParamData($params) { - $productInfo = $this->productCodeAndType->get($params['type'], $params['option'], $params['country']); + $productInfo = $this->productInfo->get($params['type'], $params['option'], $params['country']); return [ 'quote_id' => isset($params['quote_id']) ? $params['quote_id'] : '', diff --git a/Observer/SalesOrderSaveAfter/CreatePostNLOrder.php b/Observer/SalesOrderSaveAfter/CreatePostNLOrder.php index 06933ee66..8d952ec2d 100644 --- a/Observer/SalesOrderSaveAfter/CreatePostNLOrder.php +++ b/Observer/SalesOrderSaveAfter/CreatePostNLOrder.php @@ -35,7 +35,7 @@ use TIG\PostNL\Api\Data\OrderInterface; use TIG\PostNL\Helper\Data; use TIG\PostNL\Model\OrderRepository; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Sales\Model\Order as MagentoOrder; @@ -60,9 +60,9 @@ class CreatePostNLOrder implements ObserverInterface private $helper; /** - * @var ProductCodeAndType + * @var ProductInfo */ - private $productCode; + private $productInfo; /** * @var ItemsToOption @@ -70,24 +70,24 @@ class CreatePostNLOrder implements ObserverInterface private $itemsToOption; /** - * @param OrderRepository $orderRepository - * @param ParcelCount $count - * @param ItemsToOption $itemsToOption - * @param ProductCodeAndType $productCode - * @param Data $helper + * @param OrderRepository $orderRepository + * @param ParcelCount $count + * @param ItemsToOption $itemsToOption + * @param ProductInfo $productInfo + * @param Data $helper */ public function __construct( OrderRepository $orderRepository, ParcelCount $count, ItemsToOption $itemsToOption, - ProductCodeAndType $productCode, + ProductInfo $productInfo, Data $helper ) { $this->orderRepository = $orderRepository; - $this->parcelCount = $count; - $this->itemsToOption = $itemsToOption; - $this->helper = $helper; - $this->productCode = $productCode; + $this->parcelCount = $count; + $this->itemsToOption = $itemsToOption; + $this->helper = $helper; + $this->productInfo = $productInfo; } /** @@ -178,12 +178,12 @@ private function setProductCode(OrderInterface $postnlOrder, MagentoOrder $magen { /** * If the product code is not set by the user then calculate it and save it also. It is possible that it is not - * set because the deliveryoptions are disabled or this is an EPS shipment. + * set because the delivery options are disabled or this is an EPS shipment. */ if (!$postnlOrder->getProductCode()) { $option = $this->itemsToOption->get($magentoOrder->getItems()); $shippingAddress = $magentoOrder->getShippingAddress(); - $productInfo = $this->productCode->get('', $option, $shippingAddress); + $productInfo = $this->productInfo->get('', $option, $shippingAddress); $postnlOrder->setProductCode($productInfo['code']); $postnlOrder->setType($productInfo['type']); } diff --git a/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php b/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php index 3b83f3f28..8679c6ffe 100644 --- a/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php +++ b/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php @@ -34,7 +34,7 @@ use TIG\PostNL\Api\Data\OrderInterface; use TIG\PostNL\Logging\Log; use TIG\PostNL\Service\Order\ShipAt; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Service\Order\FirstDeliveryDate; use TIG\PostNL\Service\Options\ItemsToOption; use TIG\PostNL\Service\Order\MagentoOrder; @@ -46,9 +46,9 @@ class SetDefaultData implements ObserverInterface { /** - * @var ProductCodeAndType + * @var ProductInfo */ - private $productCodeAndType; + private $productInfo; /** * @var FirstDeliveryDate @@ -84,22 +84,22 @@ class SetDefaultData implements ObserverInterface * @var array */ private $shouldUpdateByOption = [ - ProductCodeAndType::OPTION_EXTRAATHOME + ProductInfo::OPTION_EXTRAATHOME ]; /** * SetDefaultData constructor. * - * @param ProductCodeAndType $productCodeAndType - * @param FirstDeliveryDate $firstDeliveryDate - * @param ShipAt $shipAt - * @param Log $log - * @param ItemsToOption $itemsToOption - * @param MagentoOrder $magentoOrder - * @param ShippingDuration $shippingDuration + * @param ProductInfo $productInfo + * @param FirstDeliveryDate $firstDeliveryDate + * @param ShipAt $shipAt + * @param Log $log + * @param ItemsToOption $itemsToOption + * @param MagentoOrder $magentoOrder + * @param ShippingDuration $shippingDuration */ public function __construct( - ProductCodeAndType $productCodeAndType, + ProductInfo $productInfo, FirstDeliveryDate $firstDeliveryDate, ShipAt $shipAt, Log $log, @@ -107,13 +107,13 @@ public function __construct( MagentoOrder $magentoOrder, ShippingDuration $shippingDuration ) { - $this->productCodeAndType = $productCodeAndType; - $this->firstDeliveryDate = $firstDeliveryDate; - $this->shipAt = $shipAt; - $this->log = $log; - $this->itemsToOption = $itemsToOption; - $this->magentoOrder = $magentoOrder; - $this->shippingDuration = $shippingDuration; + $this->productInfo = $productInfo; + $this->firstDeliveryDate = $firstDeliveryDate; + $this->shipAt = $shipAt; + $this->log = $log; + $this->itemsToOption = $itemsToOption; + $this->magentoOrder = $magentoOrder; + $this->shippingDuration = $shippingDuration; } /** @@ -132,15 +132,17 @@ public function execute(Observer $observer) $this->log->critical($exception->getTraceAsString()); } } - - /** - * @param $order - */ + + /** + * @param \TIG\PostNL\Api\Data\OrderInterface $order + * + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ private function setData(OrderInterface $order) { $option = $this->getOptionFromQuote(); $address = $this->checkByAddressData($order); - $productInfo = $this->productCodeAndType->get('', $option, $address); + $productInfo = $this->productInfo->get('', $option, $address); $duration = $this->shippingDuration->get(); if (!$order->getProductCode() || $this->canUpdate($order->getProductCode(), $productInfo['code'], $option)) { diff --git a/Service/Options/ItemsToOption.php b/Service/Options/ItemsToOption.php index 40bb1d8be..236c35c1d 100644 --- a/Service/Options/ItemsToOption.php +++ b/Service/Options/ItemsToOption.php @@ -32,7 +32,7 @@ namespace TIG\PostNL\Service\Options; use TIG\PostNL\Config\Provider\ProductType; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Service\Wrapper\QuoteInterface; use Magento\Sales\Api\Data\ShipmentItemInterface; use Magento\Quote\Model\ResourceModel\Quote\Item as QuoteItem; @@ -41,7 +41,7 @@ class ItemsToOption { private $typeToOption = [ - ProductType::PRODUCT_TYPE_EXTRA_AT_HOME => ProductCodeAndType::OPTION_EXTRAATHOME, + ProductType::PRODUCT_TYPE_EXTRA_AT_HOME => ProductInfo::OPTION_EXTRAATHOME, ProductType::PRODUCT_TYPE_REGULAR => '', ]; diff --git a/Service/Shipment/Label/Generate.php b/Service/Shipment/Label/Generate.php index ba84b6fda..3ab90eae1 100644 --- a/Service/Shipment/Label/Generate.php +++ b/Service/Shipment/Label/Generate.php @@ -31,7 +31,7 @@ */ namespace TIG\PostNL\Service\Shipment\Label; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Api\Data\ShipmentLabelInterface; class Generate @@ -92,7 +92,7 @@ public function orderLabels($labels) { $otherLabels = array_filter($labels, function ($label) { /** @var ShipmentLabelInterface $label */ - if (strtoupper($label->getType()) == ProductCodeAndType::SHIPMENT_TYPE_GP) { + if (strtoupper($label->getType()) == ProductInfo::SHIPMENT_TYPE_GP) { $this->globalPackLabels[] = $label; return false; } diff --git a/Service/Shipment/Packingslip/MergeWithLabels.php b/Service/Shipment/Packingslip/MergeWithLabels.php index 4e0ee7c70..dd85691ef 100644 --- a/Service/Shipment/Packingslip/MergeWithLabels.php +++ b/Service/Shipment/Packingslip/MergeWithLabels.php @@ -32,7 +32,7 @@ namespace TIG\PostNL\Service\Shipment\Packingslip; use TIG\PostNL\Api\Data\ShipmentLabelInterface; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Service\Pdf\Fpdi; use TIG\PostNL\Service\Pdf\FpdiFactory; use TIG\PostNL\Service\Shipment\Label\File; @@ -152,7 +152,7 @@ public function merge($shipmentId, $packingslip, $mergeFirstLabel = false, $conf */ private function canMergeFirstLabel($firstLabel) { - $labelTypeGP = strtolower(ProductCodeAndType::SHIPMENT_TYPE_GP); + $labelTypeGP = strtolower(ProductInfo::SHIPMENT_TYPE_GP); if ($this->packingslipYPos <= 400 || $firstLabel->getType() == $labelTypeGP) { return false; } @@ -204,7 +204,7 @@ private function mergeFirstLabel($label, $packingslip, $type = null) */ private function addLabelToPdf($labelFile, Fpdi $pdf, $type) { - if ($type == strtolower(ProductCodeAndType::SHIPMENT_TYPE_EPS)) { + if ($type == strtolower(ProductInfo::SHIPMENT_TYPE_EPS)) { $this->setEpsPosition(); } diff --git a/Test/Integration/Observer/SetDefaultDataTest.php b/Test/Integration/Observer/SetDefaultDataTest.php index 787f7964c..4f8ea9195 100644 --- a/Test/Integration/Observer/SetDefaultDataTest.php +++ b/Test/Integration/Observer/SetDefaultDataTest.php @@ -38,7 +38,7 @@ use TIG\PostNL\Webservices\Endpoints\SentDate; use TIG\PostNL\Webservices\Endpoints\DeliveryDate; use TIG\PostNL\Service\Options\ItemsToOption; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use Magento\Framework\Event\Observer; use TIG\PostNL\Service\Order\MagentoOrder; use TIG\PostNL\Service\Quote\ShippingDuration; @@ -71,9 +71,9 @@ public function testExecute() $itemsToOptions->disableOriginalConstructor(); $itemsToOptions = $itemsToOptions->getMock(); - $productCodeAndType = $this->getMockBuilder(ProductCodeAndType::class); - $productCodeAndType->disableOriginalConstructor(); - $productCodeAndType = $productCodeAndType->getMock(); + $productInfo = $this->getMockBuilder(ProductInfo::class); + $productInfo->disableOriginalConstructor(); + $productInfo = $productInfo->getMock(); $magentoOrderService = $this->getMockBuilder(MagentoOrder::class); $magentoOrderService->disableOriginalConstructor(); @@ -85,9 +85,9 @@ public function testExecute() $this->objectManager->configure([ 'preferences' => [ - ProductCodeAndType::class => get_class($productCodeAndType), - ItemsToOption::class => get_class($itemsToOptions), - MagentoOrder::class => get_class($magentoOrderService), + ProductInfo::class => get_class($productInfo), + ItemsToOption::class => get_class($itemsToOptions), + MagentoOrder::class => get_class($magentoOrderService), ShippingDuration::class => get_class($shippingDuration) ], ]); @@ -102,11 +102,11 @@ public function testExecute() $magentoServiceGetAddress->method('getShippingAddress')->willReturn($address); $getFromQuote = $this->objectManager->get(ItemsToOption::class); - $getFromQuote->method('getFromQuote')->willReturn(ProductCodeAndType::OPTION_EXTRAATHOME); + $getFromQuote->method('getFromQuote')->willReturn(ProductInfo::OPTION_EXTRAATHOME); - $getProductInfo = $this->objectManager->get(ProductCodeAndType::class); + $getProductInfo = $this->objectManager->get(ProductInfo::class); $getProductInfo->method('get')->willReturn([ - 'type' => ProductCodeAndType::SHIPMENT_TYPE_EXTRAATHOME, + 'type' => ProductInfo::SHIPMENT_TYPE_EXTRAATHOME, 'code' => 3085 ]); @@ -123,7 +123,7 @@ public function testExecute() $this->getInstance()->execute($observer); $this->assertEquals(3085, $postNLOrder->getProductCode()); - $this->assertEquals(ProductCodeAndType::SHIPMENT_TYPE_EXTRAATHOME, $postNLOrder->getType()); + $this->assertEquals(ProductInfo::SHIPMENT_TYPE_EXTRAATHOME, $postNLOrder->getType()); } /** @@ -138,7 +138,7 @@ private function getPostNLOrder() if (!$postNLOrder) { $postNLOrder = $orderRepository->create(); $postNLOrder->setProductCode(3085); - $postNLOrder->setType(ProductCodeAndType::SHIPMENT_TYPE_DAYTIME); + $postNLOrder->setType(ProductInfo::SHIPMENT_TYPE_DAYTIME); } $postNLOrder->setDeliveryDate('2017-11-06 01:00:00'); diff --git a/Test/Integration/Service/Options/ItemsToOptionTest.php b/Test/Integration/Service/Options/ItemsToOptionTest.php index ac8aa7fd1..dff01be10 100644 --- a/Test/Integration/Service/Options/ItemsToOptionTest.php +++ b/Test/Integration/Service/Options/ItemsToOptionTest.php @@ -34,7 +34,7 @@ use TIG\PostNL\Test\Integration\TestCase; use Magento\Sales\Model\ResourceModel\Order\Collection; use TIG\PostNL\Service\Options\ItemsToOption; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; class ItemsToOptionTest extends TestCase { @@ -48,7 +48,7 @@ public function testGetWithExtraAtHomeOrder() $order = $this->getOrder(); $result = $this->getInstance()->get($order->getItems()); - $this->assertEquals(ProductCodeAndType::OPTION_EXTRAATHOME, $result); + $this->assertEquals(ProductInfo::OPTION_EXTRAATHOME, $result); } public function testReqularOrder() diff --git a/Test/Unit/Config/CheckoutConfiguration/IsShippingOptionsActiveTest.php b/Test/Unit/Config/CheckoutConfiguration/IsShippingOptionsActiveTest.php index 1be0c1223..3ba6fe20c 100644 --- a/Test/Unit/Config/CheckoutConfiguration/IsShippingOptionsActiveTest.php +++ b/Test/Unit/Config/CheckoutConfiguration/IsShippingOptionsActiveTest.php @@ -36,7 +36,7 @@ use TIG\PostNL\Config\Provider\AccountConfiguration; use TIG\PostNL\Config\Provider\ShippingOptions; use TIG\PostNL\Service\Quote\CheckIfQuoteHasOption; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Test\TestCase; class IsShippingOptionsActiveTest extends TestCase @@ -680,7 +680,7 @@ public function testGetValue( $quoteHasOption = $this->getFakeMock(CheckIfQuoteHasOption::class)->getMock(); $extraAtHomeGetValueExpects = $quoteHasOption->method('get'); - $extraAtHomeGetValueExpects->with(ProductCodeAndType::OPTION_EXTRAATHOME); + $extraAtHomeGetValueExpects->with(ProductInfo::OPTION_EXTRAATHOME); $extraAtHomeGetValueExpects->willReturn($isExtraAtHome); /** @var IsShippingOptionsActive $instance */ diff --git a/Test/Unit/Helper/DeliveryOptions/OrderParamsTest.php b/Test/Unit/Helper/DeliveryOptions/OrderParamsTest.php index 36eb05c1d..9f89ea8d0 100644 --- a/Test/Unit/Helper/DeliveryOptions/OrderParamsTest.php +++ b/Test/Unit/Helper/DeliveryOptions/OrderParamsTest.php @@ -34,7 +34,7 @@ use TIG\PostNL\Test\TestCase; use TIG\PostNL\Helper\DeliveryOptions\OrderParams; use TIG\PostNL\Service\Order\FeeCalculator; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Service\Shipment\ProductOptions; class OrderParamsTest extends TestCase @@ -53,13 +53,13 @@ class OrderParamsTest extends TestCase public function testGet() { - $productInfo = [ + $productMock = [ 'code' => '3085', 'type' => 'Daytime', ]; - $productCodeAndTypeMock = $this->getFakeMock(ProductCodeAndType::class)->getMock(); - $productCodeAndTypeMock->expects($this->once())->method('get')->willReturn($productInfo); + $productInfoMock = $this->getFakeMock(ProductInfo::class)->getMock(); + $productInfoMock->expects($this->once())->method('get')->willReturn($productMock); $feeCalculatorMock = $this->getFakeMock(FeeCalculator::class)->getMock(); $feeCalculatorMock->expects($this->once())->method('get')->willReturn(0.0); @@ -69,7 +69,7 @@ public function testGet() $instance = $this->getInstance([ 'feeCalculator' => $feeCalculatorMock, - 'productCodeAndType' => $productCodeAndTypeMock, + 'productInfo' => $productInfoMock, 'productOptions' => $productOptionsMock ]); diff --git a/Test/Unit/Service/Carrier/ParcelTypeFinderTest.php b/Test/Unit/Service/Carrier/ParcelTypeFinderTest.php index 714113fc5..d0dd94166 100644 --- a/Test/Unit/Service/Carrier/ParcelTypeFinderTest.php +++ b/Test/Unit/Service/Carrier/ParcelTypeFinderTest.php @@ -34,7 +34,7 @@ use TIG\PostNL\Api\Data\OrderInterface; use TIG\PostNL\Api\OrderRepositoryInterface; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Test\TestCase; class ParcelTypeFinderTest extends TestCase @@ -43,13 +43,13 @@ class ParcelTypeFinderTest extends TestCase public function testFindsExtraAtHome() { - $itemsToOption = $this->mockItemsToOption(ProductCodeAndType::OPTION_EXTRAATHOME); + $itemsToOption = $this->mockItemsToOption(ProductInfo::OPTION_EXTRAATHOME); $instance = $this->getInstance([ 'itemsToOption' => $itemsToOption, ]); - $this->assertEquals(ProductCodeAndType::OPTION_EXTRAATHOME, $instance->get()); + $this->assertEquals(ProductInfo::OPTION_EXTRAATHOME, $instance->get()); } public function testPakjegemakIsReturned() diff --git a/Test/Unit/Service/Order/ProductCodeTest.php b/Test/Unit/Service/Order/ProductCodeTest.php index 5424a19b0..dc756b58c 100644 --- a/Test/Unit/Service/Order/ProductCodeTest.php +++ b/Test/Unit/Service/Order/ProductCodeTest.php @@ -33,7 +33,7 @@ use Magento\Quote\Model\Quote; use TIG\PostNL\Config\Provider\ProductOptions; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Service\Wrapper\QuoteInterface; use TIG\PostNL\Test\TestCase; @@ -62,7 +62,7 @@ class ProductCodeTest extends TestCase */ private $quoteInterfaceMock; - public $instanceClass = ProductCodeAndType::class; + public $instanceClass = ProductInfo::class; public function setUp() { diff --git a/Test/Unit/Service/Quote/CheckIfQuoteHasOptionTest.php b/Test/Unit/Service/Quote/CheckIfQuoteHasOptionTest.php index 56bfa4139..9574e323f 100644 --- a/Test/Unit/Service/Quote/CheckIfQuoteHasOptionTest.php +++ b/Test/Unit/Service/Quote/CheckIfQuoteHasOptionTest.php @@ -34,7 +34,7 @@ use TIG\PostNL\Service\Quote\CheckIfQuoteHasOption; use Magento\Checkout\Model\Session as CheckoutSession; use TIG\PostNL\Service\Options\ItemsToOption; -use TIG\PostNL\Service\Order\ProductCodeAndType; +use TIG\PostNL\Service\Order\ProductInfo; use TIG\PostNL\Test\TestCase; class CheckIfQuoteHasOptionTest extends TestCase @@ -47,8 +47,8 @@ class CheckIfQuoteHasOptionTest extends TestCase public function getDataProvider() { return [ - 'Extra@Home with quote' => [ProductCodeAndType::OPTION_EXTRAATHOME, true, true], - 'Extra@Home no quote' => [ProductCodeAndType::OPTION_EXTRAATHOME, false, false] + 'Extra@Home with quote' => [ProductInfo::OPTION_EXTRAATHOME, true, true], + 'Extra@Home no quote' => [ProductInfo::OPTION_EXTRAATHOME, false, false] ]; } From 1e49907f3b16efd6db20993f8ae745700b3ebd98 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 28 Feb 2019 10:41:34 +0100 Subject: [PATCH 024/113] Fixed typo in ProductCodeTest --- Test/Unit/Service/Order/ProductCodeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Unit/Service/Order/ProductCodeTest.php b/Test/Unit/Service/Order/ProductCodeTest.php index dc756b58c..24349d665 100644 --- a/Test/Unit/Service/Order/ProductCodeTest.php +++ b/Test/Unit/Service/Order/ProductCodeTest.php @@ -201,7 +201,7 @@ public function testGetDefaultProductOption($useAlternative, $alternativeMinAmou $this->productOptionsMock->method('getAlternativeDefaultMinAmount')->willReturn($alternativeMinAmount); $instance = $this->getInstance(); - $this->invokeArgs('getDefaultProductOption', ['country' => 'NL'], $instance); + $this->invokeArgs('setDefaultProductOption', ['country' => 'NL'], $instance); $resultCode = $this->getProperty('code', $instance); $resultType = $this->getProperty('type', $instance); From 2d87f2ed4752326378bdb5c21d4b17c8146d366f Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 28 Feb 2019 10:59:16 +0100 Subject: [PATCH 025/113] Fixed expected results in ProductCodeTest as there's no mention of default_eps_product_option anywhere in the code. --- Test/Unit/Service/Order/ProductCodeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Unit/Service/Order/ProductCodeTest.php b/Test/Unit/Service/Order/ProductCodeTest.php index 24349d665..c7c6d6e21 100644 --- a/Test/Unit/Service/Order/ProductCodeTest.php +++ b/Test/Unit/Service/Order/ProductCodeTest.php @@ -44,7 +44,7 @@ class ProductCodeTest extends TestCase { const PRODUCT_OPTION_DEFAULT = 'default_product_option'; const PRODUCT_OPTION_BE_DEFAULT = 'default_be_product_option'; - const PRODUCT_OPTION_EPS_DEFAULT = 'default_eps_product_option'; + const PRODUCT_OPTION_EPS_DEFAULT = '4952'; const PRODUCT_OPTION_ALTERNATIVE_DEFAULT = 'alternative_default_product_option'; const PRODUCT_OPTION_EVENING = 'evening_product_option'; const PRODUCT_OPTION_EXTRAATHOME = 'extraathome_product_option'; From ac6d3c327f9731f96e0cedf764838b366af2c0b4 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 5 Mar 2019 10:55:16 +0100 Subject: [PATCH 026/113] Removed hardcoded 4945 and replaced it getter. --- Service/Order/ProductInfo.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Service/Order/ProductInfo.php b/Service/Order/ProductInfo.php index 53f1e7bed..2d1cfe0ba 100644 --- a/Service/Order/ProductInfo.php +++ b/Service/Order/ProductInfo.php @@ -192,9 +192,10 @@ private function setEpsOption($address, $country) { $this->type = static::SHIPMENT_TYPE_EPS; // Force type Global Pack (mainly used for Canary Islands) - $options = $this->productOptionsFinder->getEpsProductOptions($address); - $firstOption = array_shift($options); - if (in_array('4945', $firstOption)) { + $options = $this->productOptionsFinder->getEpsProductOptions($address); + $firstOption = array_shift($options); + $globalPackOption = $this->productOptionsFinder->getDefaultGPOption()['value']; + if (in_array($globalPackOption, $firstOption)) { $this->setGlobalPackOption(); return; From d5dcc5919cd1de9794c41f3347ee219bd4157918 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 7 Mar 2019 13:24:37 +0100 Subject: [PATCH 027/113] POSTNLM2-771: Fixed bug where PEPS orders couldn't generate labels. --- Service/Handler/BarcodeHandler.php | 2 ++ Service/Shipment/Label/Validator.php | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Service/Handler/BarcodeHandler.php b/Service/Handler/BarcodeHandler.php index 543109661..09bad8089 100644 --- a/Service/Handler/BarcodeHandler.php +++ b/Service/Handler/BarcodeHandler.php @@ -179,6 +179,8 @@ private function setTypeByProductCode($code) { if ($this->productOptionsConfiguration->checkProductByFlags($code, 'group', 'peps_options')) { $this->barcodeEndpoint->setType('PEPS'); + + return; } $this->barcodeEndpoint->setType(''); diff --git a/Service/Shipment/Label/Validator.php b/Service/Shipment/Label/Validator.php index 962fcb3ca..b75868cf0 100644 --- a/Service/Shipment/Label/Validator.php +++ b/Service/Shipment/Label/Validator.php @@ -142,10 +142,8 @@ private function validateProductCode(ShipmentInterface $shipment) } if ($isPeps && $shipment->getParcelCount() < 5) { - $magentoShipment = $shipment->getShipment(); // @codingStandardsIgnoreLine - $this->errors[] = __('Could not print labels for shipment %1. Priority Delivery requires a minimum of parcels/colli.', $magentoShipment->getIncrementId()); - return false; + $this->errors[] = __('A Priority Delivery requires a minimum of 5 parcels/packages.'); } return true; From 35d0f498c63d10a9b9a10d431b70f15aec0a3190 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 13:02:52 +0100 Subject: [PATCH 028/113] Re-factored PEPS to Priority to prevent confusion and increase readability. --- Config/Source/Options/DefaultOptions.php | 6 +++--- Config/Source/Options/ProductOptions.php | 6 +++--- Service/Order/ProductInfo.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Config/Source/Options/DefaultOptions.php b/Config/Source/Options/DefaultOptions.php index 3e2bb590a..fbd5452d7 100644 --- a/Config/Source/Options/DefaultOptions.php +++ b/Config/Source/Options/DefaultOptions.php @@ -92,7 +92,7 @@ public function toOptionArray() */ public function getBeProducts() { - $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPepsOptions() : []; + $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; $epsBusinessOptions = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; $cargoOptions = $this->shippingOptions->canUseCargoProducts() ? $this->productOptions->getCargoOptions() : []; @@ -111,7 +111,7 @@ public function getBeProducts() */ public function getEpsProducts() { - $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPepsOptions() : []; + $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; $epsBusinessOptions = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; $epsProducts = [ @@ -128,7 +128,7 @@ public function getEpsProducts() */ public function getGlobalProducts() { - $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPepsOptions() : []; + $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; $globalProducts = [ $this->productOptions->getGlobalPackOptions(), diff --git a/Config/Source/Options/ProductOptions.php b/Config/Source/Options/ProductOptions.php index 62f300bcf..5f108f4a6 100644 --- a/Config/Source/Options/ProductOptions.php +++ b/Config/Source/Options/ProductOptions.php @@ -187,11 +187,11 @@ public function getEpsOptions() /** * @return array */ - public function getPepsOptions() + public function getPriorityOptions() { - $pepsOptions = $this->getProductOptions(['group' => 'peps_options']); + $priorityOptions = $this->getProductOptions(['group' => 'peps_options']); - return $pepsOptions; + return $priorityOptions; } /** diff --git a/Service/Order/ProductInfo.php b/Service/Order/ProductInfo.php index 2d1cfe0ba..1fe9644b1 100644 --- a/Service/Order/ProductInfo.php +++ b/Service/Order/ProductInfo.php @@ -38,7 +38,7 @@ use TIG\PostNL\Config\Provider\ProductOptions as ProductOptionsConfiguration; use TIG\PostNL\Config\Source\Options\ProductOptions as ProductOptionsFinder; use TIG\PostNL\Service\Shipment\EpsCountries; -use TIG\PostNL\Service\Shipment\PepsCountries; +use TIG\PostNL\Service\Shipment\PriorityCountries; use TIG\PostNL\Service\Wrapper\QuoteInterface; // @codingStandardsIgnoreFile @@ -175,7 +175,7 @@ private function setGlobalPackOption($country = null) { $this->type = static::SHIPMENT_TYPE_GP; $this->code = $this->productOptionsConfiguration->getDefaultGlobalpackOption(); - if (in_array($country, PepsCountries::GLOBALPACK) + if (in_array($country, PriorityCountries::GLOBALPACK) && $this->isPriorityProduct($this->code) ) { return; @@ -202,7 +202,7 @@ private function setEpsOption($address, $country) { } $this->code = $this->productOptionsConfiguration->getDefaultEpsProductOption(); - if (in_array($country, PepsCountries::EPS) + if (in_array($country, PriorityCountries::EPS) && $this->isPriorityProduct($this->code) ) { return; From beccdc51fbd9ed24782e49a4b51fba7129e177dd Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 13:03:19 +0100 Subject: [PATCH 029/113] Small re-factor and removed BE from Priority EPS. --- .../Shipment/{PepsCountries.php => PriorityCountries.php} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename Service/Shipment/{PepsCountries.php => PriorityCountries.php} (93%) diff --git a/Service/Shipment/PepsCountries.php b/Service/Shipment/PriorityCountries.php similarity index 93% rename from Service/Shipment/PepsCountries.php rename to Service/Shipment/PriorityCountries.php index c05977af3..bc3b98af0 100644 --- a/Service/Shipment/PepsCountries.php +++ b/Service/Shipment/PriorityCountries.php @@ -31,7 +31,7 @@ */ namespace TIG\PostNL\Service\Shipment; -class PepsCountries +class PriorityCountries { /** * PEPS uses his own EPS and Globalpack countries. Which is different than @@ -68,9 +68,12 @@ class PepsCountries ]; // NOT ROW + /** + * Belgium does't have to be enlisted in priority, because regular EPS + * can already deliver to BE in one day. + */ const EPS = [ 'AT', - 'BE', 'CY', 'DE', 'DK', From 268237797f7bff9babf50a09e3814e8b67c107c0 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 13:03:54 +0100 Subject: [PATCH 030/113] POSTNLM2-774: Add Priority Options to Create Shipment screen. --- Service/Options/ShipmentSupported.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index 9e4b8bad6..94144bdd7 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -34,6 +34,7 @@ use TIG\PostNL\Config\Source\Options\ProductOptions; use TIG\PostNL\Config\Provider\ProductOptions as OptionsProvider; use TIG\PostNL\Service\Shipment\EpsCountries; +use TIG\PostNL\Service\Shipment\PriorityCountries; class ShipmentSupported { @@ -96,17 +97,24 @@ private function availableOptions($country) private function getProductOptionsByCountry($country) { + $options = []; if (in_array($country, $this->allowedCountries)) { - $options = $this->getProductOptions($country); - return $options; + $options[] = array_merge($options, $this->getProductOptions($country)); } - + if (in_array($country, EpsCountries::ALL)) { - $options = $this->productOptions->getEpsProductOptions(); - return $options; + $options[] = array_merge($options, $this->productOptions->getEpsProductOptions()); } - - $options = $this->productOptions->getGlobalPackOptions(); + + if (in_array($country, array_merge(PriorityCountries::GLOBALPACK, PriorityCountries::EPS))) { + $options[] = array_merge($options, $this->productOptions->getPriorityOptions()); + } + + if (!in_array($country, EpsCountries::ALL)) { + $options[] = array_merge($options, $this->productOptions->getGlobalPackOptions()); + } + + $options = call_user_func_array("array_merge", $options); return $options; } From 57bf6f2b82a13e662d0d87ef4cf75c4c10cb7b84 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 13:08:51 +0100 Subject: [PATCH 031/113] Re-factored peps_options to priority_options for naming consistency. --- Config/Source/Options/ProductOptions.php | 2 +- Config/Source/OptionsAbstract.php | 56 ++++++++++++------------ Service/Handler/BarcodeHandler.php | 2 +- Service/Order/ProductInfo.php | 2 +- Service/Shipment/Label/Validator.php | 2 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Config/Source/Options/ProductOptions.php b/Config/Source/Options/ProductOptions.php index 5f108f4a6..c27bf21a7 100644 --- a/Config/Source/Options/ProductOptions.php +++ b/Config/Source/Options/ProductOptions.php @@ -189,7 +189,7 @@ public function getEpsOptions() */ public function getPriorityOptions() { - $priorityOptions = $this->getProductOptions(['group' => 'peps_options']); + $priorityOptions = $this->getProductOptions(['group' => 'priority_options']); return $priorityOptions; } diff --git a/Config/Source/OptionsAbstract.php b/Config/Source/OptionsAbstract.php index cb1920a97..68f259417 100644 --- a/Config/Source/OptionsAbstract.php +++ b/Config/Source/OptionsAbstract.php @@ -605,7 +605,7 @@ abstract class OptionsAbstract 'isSunday' => false, 'isGuaranteedDelivery' => false, 'countryLimitation' => false, - 'group' => 'peps_options', + 'group' => 'priority_options', ], '6550' => [ 'value' => '6550', @@ -615,7 +615,7 @@ abstract class OptionsAbstract 'isSunday' => false, 'isGuaranteedDelivery' => false, 'countryLimitation' => false, - 'group' => 'peps_options', + 'group' => 'priority_options', ], '6940' => [ 'value' => '6940', @@ -625,7 +625,7 @@ abstract class OptionsAbstract 'isSunday' => false, 'isGuaranteedDelivery' => false, 'countryLimitation' => false, - 'group' => 'peps_options', + 'group' => 'priority_options', ], '6942' => [ 'value' => '6942', @@ -635,36 +635,36 @@ abstract class OptionsAbstract 'isSunday' => false, 'isGuaranteedDelivery' => false, 'countryLimitation' => false, - 'group' => 'peps_options', + 'group' => 'priority_options', ] ]; protected $groups = [ - 'standard_options' => 'Domestic options', - 'pakjegemak_options' => 'Post Office options', - 'eu_options' => 'EU options', - 'global_options' => 'Global options', - 'buspakje_options' => 'Letter Box Parcel options', - 'extra_at_home_options' => 'Extra@Home options', - 'id_check_options' => 'ID Check options', - 'id_check_pakjegemak_options' => 'ID Check Post Office options', - 'cargo_options' => 'Cargo options', - 'eps_package_options' => 'Package options', - 'peps_options' => 'Priority EPS' + 'standard_options' => 'Domestic options', + 'pakjegemak_options' => 'Post Office options', + 'eu_options' => 'EU options', + 'global_options' => 'Global options', + 'buspakje_options' => 'Letter Box Parcel options', + 'extra_at_home_options' => 'Extra@Home options', + 'id_check_options' => 'ID Check options', + 'id_check_pakjegemak_options' => 'ID Check Post Office options', + 'cargo_options' => 'Cargo options', + 'eps_package_options' => 'Package options', + 'priority_options' => 'Priority EPS' ]; - - protected $groupToLabel = [ - 'standard_options' => 'Domestic', - 'pakjegemak_options' => 'Post Office', - 'eu_options' => 'EPS', - 'global_options' => 'Global Pack', - 'buspakje_options' => 'Letter Box', - 'extra_at_home_options' => 'Extra@Home', - 'id_check_options' => 'ID Check', - 'id_check_pakjegemak_options' => 'ID Check Post Office', - 'cargo_options' => 'Cargo', - 'eps_package_options' => 'Package', - 'peps_options' => 'Priority (EPS / Globalpack)' + + protected $groupToLabel = [ + 'standard_options' => 'Domestic', + 'pakjegemak_options' => 'Post Office', + 'eu_options' => 'EPS', + 'global_options' => 'Global Pack', + 'buspakje_options' => 'Letter Box', + 'extra_at_home_options' => 'Extra@Home', + 'id_check_options' => 'ID Check', + 'id_check_pakjegemak_options' => 'ID Check Post Office', + 'cargo_options' => 'Cargo', + 'eps_package_options' => 'Package', + 'priority_options' => 'Priority (EPS / Globalpack)' ]; protected $typeToComment = [ diff --git a/Service/Handler/BarcodeHandler.php b/Service/Handler/BarcodeHandler.php index 09bad8089..56ff05b0f 100644 --- a/Service/Handler/BarcodeHandler.php +++ b/Service/Handler/BarcodeHandler.php @@ -177,7 +177,7 @@ private function generate(ShipmentInterface $shipment) */ private function setTypeByProductCode($code) { - if ($this->productOptionsConfiguration->checkProductByFlags($code, 'group', 'peps_options')) { + if ($this->productOptionsConfiguration->checkProductByFlags($code, 'group', 'priority_options')) { $this->barcodeEndpoint->setType('PEPS'); return; diff --git a/Service/Order/ProductInfo.php b/Service/Order/ProductInfo.php index 1fe9644b1..e03860f42 100644 --- a/Service/Order/ProductInfo.php +++ b/Service/Order/ProductInfo.php @@ -219,7 +219,7 @@ private function setEpsOption($address, $country) { * @return bool|null */ private function isPriorityProduct($code) { - return $this->productOptionsConfiguration->checkProductByFlags($code, 'group', 'peps_options'); + return $this->productOptionsConfiguration->checkProductByFlags($code, 'group', 'priority_options'); } /** diff --git a/Service/Shipment/Label/Validator.php b/Service/Shipment/Label/Validator.php index b75868cf0..b24662a50 100644 --- a/Service/Shipment/Label/Validator.php +++ b/Service/Shipment/Label/Validator.php @@ -132,7 +132,7 @@ private function validateGlobalPack(ShipmentInterface $shipment) private function validateProductCode(ShipmentInterface $shipment) { $code = $shipment->getProductCode(); - $isPeps = $this->productOptions->checkProductByFlags($code, 'group', 'peps_options'); + $isPeps = $this->productOptions->checkProductByFlags($code, 'group', 'priority_options'); if ($isPeps && !$this->shippingOptions->canUsePepsProducts()) { $magentoShipment = $shipment->getShipment(); From adaa2594db286c7d2c9e677f65772090e324e380 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 14:03:42 +0100 Subject: [PATCH 032/113] Spaces must be used to indent lines. Tabs are not allowed. --- Service/Options/ShipmentSupported.php | 57 +++++++++++++------------- Service/Shipment/PriorityCountries.php | 17 ++++---- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index 94144bdd7..ec7d45ed3 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -29,6 +29,7 @@ * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ + namespace TIG\PostNL\Service\Options; use TIG\PostNL\Config\Source\Options\ProductOptions; @@ -36,23 +37,22 @@ use TIG\PostNL\Service\Shipment\EpsCountries; use TIG\PostNL\Service\Shipment\PriorityCountries; -class ShipmentSupported -{ +class ShipmentSupported { /** * @var ProductOptions */ private $productOptions; - + /** * @var OptionsProvider */ private $optionsProvider; - + /** * @var array */ private $allowedCountries = ['NL', 'BE']; - + public function __construct( ProductOptions $productOptions, OptionsProvider $optionsProvider @@ -60,44 +60,44 @@ public function __construct( $this->productOptions = $productOptions; $this->optionsProvider = $optionsProvider; } - + /** * @param \Magento\Sales\Api\Data\OrderInterface|\Magento\Sales\Model\Order $order + * * @return array */ - public function get($order) - { + public function get($order) { $address = $order->getShippingAddress(); + return $this->availableOptions($address->getCountryId()); } - + /** * @param $country * * @return array */ - private function availableOptions($country) - { + private function availableOptions($country) { // These are the options selected in the configuration by user. $supportedOptions = $this->optionsProvider->getSupportedProductOptions(); - + $optionsAllowed = $this->getProductOptionsByCountry($country); - - $availableOptions = array_filter($supportedOptions, function ($value) use ($optionsAllowed) { + + $availableOptions = array_filter($supportedOptions, function ($value) use ($optionsAllowed) + { $available = false; foreach ($optionsAllowed as $option) { $available = ($available || (isset($option['value']) && $option['value'] == $value)); } - + return $available; }); - + return $availableOptions; } - - private function getProductOptionsByCountry($country) - { - $options = []; + + private function getProductOptionsByCountry($country) { + $options = []; if (in_array($country, $this->allowedCountries)) { $options[] = array_merge($options, $this->getProductOptions($country)); } @@ -107,26 +107,27 @@ private function getProductOptionsByCountry($country) } if (in_array($country, array_merge(PriorityCountries::GLOBALPACK, PriorityCountries::EPS))) { - $options[] = array_merge($options, $this->productOptions->getPriorityOptions()); + $options[] = array_merge($options, $this->productOptions->getPriorityOptions()); } - + if (!in_array($country, EpsCountries::ALL)) { - $options[] = array_merge($options, $this->productOptions->getGlobalPackOptions()); + $options[] = array_merge($options, $this->productOptions->getGlobalPackOptions()); } - $options = call_user_func_array("array_merge", $options); + return $options; } - + /** * @param $country * * @return array */ - private function getProductOptions($country) - { + private function getProductOptions($country) { $options = $this->productOptions->get(); - return array_filter($options, function ($value) use ($country) { + + return array_filter($options, function ($value) use ($country) + { return ($value['countryLimitation'] == $country); }); } diff --git a/Service/Shipment/PriorityCountries.php b/Service/Shipment/PriorityCountries.php index bc3b98af0..7bb5ac8f1 100644 --- a/Service/Shipment/PriorityCountries.php +++ b/Service/Shipment/PriorityCountries.php @@ -29,10 +29,10 @@ * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ + namespace TIG\PostNL\Service\Shipment; -class PriorityCountries -{ +class PriorityCountries { /** * PEPS uses his own EPS and Globalpack countries. Which is different than * \TIG\PostNL\Service\Shipment\EpsCountries @@ -41,7 +41,7 @@ class PriorityCountries * * https://jira.tig.nl/browse/POSTNLM2-741 */ - + // ROW const GLOBALPACK = [ 'AU', @@ -66,12 +66,13 @@ class PriorityCountries 'TR', 'US' ]; - + // NOT ROW - /** - * Belgium does't have to be enlisted in priority, because regular EPS - * can already deliver to BE in one day. - */ + + /** + * Belgium does't have to be enlisted in priority, because regular EPS + * can already deliver to BE in one day. + */ const EPS = [ 'AT', 'CY', From 22c28db1f2de9a2e3309d1b98814ddbecedcaf4f Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 14:19:08 +0100 Subject: [PATCH 033/113] Spaces must be used to indent lines --- Service/Options/ShipmentSupported.php | 23 ++++++++++++++--------- Service/Shipment/PriorityCountries.php | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index ec7d45ed3..bb7f2612a 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -37,7 +37,8 @@ use TIG\PostNL\Service\Shipment\EpsCountries; use TIG\PostNL\Service\Shipment\PriorityCountries; -class ShipmentSupported { +class ShipmentSupported +{ /** * @var ProductOptions */ @@ -66,7 +67,8 @@ public function __construct( * * @return array */ - public function get($order) { + public function get($order) + { $address = $order->getShippingAddress(); return $this->availableOptions($address->getCountryId()); @@ -77,14 +79,14 @@ public function get($order) { * * @return array */ - private function availableOptions($country) { + private function availableOptions($country) + { // These are the options selected in the configuration by user. $supportedOptions = $this->optionsProvider->getSupportedProductOptions(); $optionsAllowed = $this->getProductOptionsByCountry($country); - $availableOptions = array_filter($supportedOptions, function ($value) use ($optionsAllowed) - { + $availableOptions = array_filter($supportedOptions, function ($value) use ($optionsAllowed) { $available = false; foreach ($optionsAllowed as $option) { $available = ($available || (isset($option['value']) && $option['value'] == $value)); @@ -96,7 +98,8 @@ private function availableOptions($country) { return $availableOptions; } - private function getProductOptionsByCountry($country) { + private function getProductOptionsByCountry($country) + { $options = []; if (in_array($country, $this->allowedCountries)) { $options[] = array_merge($options, $this->getProductOptions($country)); @@ -113,7 +116,9 @@ private function getProductOptionsByCountry($country) { if (!in_array($country, EpsCountries::ALL)) { $options[] = array_merge($options, $this->productOptions->getGlobalPackOptions()); } + // phpcs:disable $options = call_user_func_array("array_merge", $options); + // phpcs:enable return $options; } @@ -123,11 +128,11 @@ private function getProductOptionsByCountry($country) { * * @return array */ - private function getProductOptions($country) { + private function getProductOptions($country) + { $options = $this->productOptions->get(); - return array_filter($options, function ($value) use ($country) - { + return array_filter($options, function ($value) use ($country) { return ($value['countryLimitation'] == $country); }); } diff --git a/Service/Shipment/PriorityCountries.php b/Service/Shipment/PriorityCountries.php index 7bb5ac8f1..6b77eae13 100644 --- a/Service/Shipment/PriorityCountries.php +++ b/Service/Shipment/PriorityCountries.php @@ -32,7 +32,8 @@ namespace TIG\PostNL\Service\Shipment; -class PriorityCountries { +class PriorityCountries +{ /** * PEPS uses his own EPS and Globalpack countries. Which is different than * \TIG\PostNL\Service\Shipment\EpsCountries From 5079cdfe01a81b20cb4d1c2f64a694d92f97408b Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 14:21:15 +0100 Subject: [PATCH 034/113] call_user_func_array is discouraged. But much cleaner, so ignore. --- Service/Options/ShipmentSupported.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index bb7f2612a..d31b7f365 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -98,6 +98,7 @@ private function availableOptions($country) return $availableOptions; } + // phpcs:disable private function getProductOptionsByCountry($country) { $options = []; @@ -116,12 +117,12 @@ private function getProductOptionsByCountry($country) if (!in_array($country, EpsCountries::ALL)) { $options[] = array_merge($options, $this->productOptions->getGlobalPackOptions()); } - // phpcs:disable + $options = call_user_func_array("array_merge", $options); - // phpcs:enable return $options; } + // phpcs:enable /** * @param $country From a7644e3ee132d73aefd8435c01abe9fd68a80f51 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 14:36:11 +0100 Subject: [PATCH 035/113] Coding Standards Ignore around function. --- Service/Options/ShipmentSupported.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index d31b7f365..7c73d3c0d 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -98,7 +98,7 @@ private function availableOptions($country) return $availableOptions; } - // phpcs:disable + // @codingStandardsIgnoreStart private function getProductOptionsByCountry($country) { $options = []; @@ -122,7 +122,8 @@ private function getProductOptionsByCountry($country) return $options; } - // phpcs:enable + // @codingStandardsIgnoreEnd + /** * @param $country From 274d6e98635366d44699e1d1b05f4c60a788253b Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 15:07:23 +0100 Subject: [PATCH 036/113] Code must not contain multiple empty lines in a row. --- Service/Options/ShipmentSupported.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index 7c73d3c0d..e9f1dc06d 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -124,7 +124,6 @@ private function getProductOptionsByCountry($country) } // @codingStandardsIgnoreEnd - /** * @param $country * From 9556d775cb3c6696e1c6f2de8b936ff68c326e74 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 15:52:09 +0100 Subject: [PATCH 037/113] Removed array_merge, to speed things up. --- Service/Options/ShipmentSupported.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index e9f1dc06d..17ddc8d50 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -101,21 +101,20 @@ private function availableOptions($country) // @codingStandardsIgnoreStart private function getProductOptionsByCountry($country) { - $options = []; if (in_array($country, $this->allowedCountries)) { - $options[] = array_merge($options, $this->getProductOptions($country)); + $options[] = $this->getProductOptions($country); } if (in_array($country, EpsCountries::ALL)) { - $options[] = array_merge($options, $this->productOptions->getEpsProductOptions()); + $options[] = $this->productOptions->getEpsProductOptions(); } if (in_array($country, array_merge(PriorityCountries::GLOBALPACK, PriorityCountries::EPS))) { - $options[] = array_merge($options, $this->productOptions->getPriorityOptions()); + $options[] = $this->productOptions->getPriorityOptions(); } if (!in_array($country, EpsCountries::ALL)) { - $options[] = array_merge($options, $this->productOptions->getGlobalPackOptions()); + $options[] = $this->productOptions->getGlobalPackOptions(); } $options = call_user_func_array("array_merge", $options); From 89e9ee68b1588d970e92fe6270877eb8aa146e81 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 8 Mar 2019 16:00:57 +0100 Subject: [PATCH 038/113] Re-factored code, cause we don't have to create separate arrays. --- Config/Source/Options/DefaultOptions.php | 39 ++++++++---------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/Config/Source/Options/DefaultOptions.php b/Config/Source/Options/DefaultOptions.php index fbd5452d7..88a041618 100644 --- a/Config/Source/Options/DefaultOptions.php +++ b/Config/Source/Options/DefaultOptions.php @@ -92,17 +92,11 @@ public function toOptionArray() */ public function getBeProducts() { - $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; - $epsBusinessOptions = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; - $cargoOptions = $this->shippingOptions->canUseCargoProducts() ? $this->productOptions->getCargoOptions() : []; - - $beProducts = [ - $this->productOptions->getEuOptions(), - $pepsOptions, - $epsBusinessOptions, - $cargoOptions - ]; - + $beProducts[] = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; + $beProducts[] = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; + $beProducts[] = $this->shippingOptions->canUseCargoProducts() ? $this->productOptions->getCargoOptions() : []; + $beProducts[] = $this->productOptions->getEuOptions(); + return call_user_func_array("array_merge", $beProducts); } @@ -111,29 +105,20 @@ public function getBeProducts() */ public function getEpsProducts() { - $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; - $epsBusinessOptions = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; - - $epsProducts = [ - $this->productOptions->getEpsOptions(), - $pepsOptions, - $epsBusinessOptions - ]; - + $epsProducts[] = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; + $epsProducts[] = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; + $epsProducts[] = $this->productOptions->getEpsOptions(); + return call_user_func_array("array_merge", $epsProducts); } - + /** * @return array */ public function getGlobalProducts() { - $pepsOptions = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; - - $globalProducts = [ - $this->productOptions->getGlobalPackOptions(), - $pepsOptions, - ]; + $globalProducts[] = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; + $globalProducts[] = $this->productOptions->getGlobalPackOptions(); return call_user_func_array("array_merge", $globalProducts); } From d3b2a13cc5787db2dc5d894d3824b23e56cdd203 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 4 Apr 2019 15:41:20 +0200 Subject: [PATCH 039/113] Upped GetSentDate webservice to v2_2. --- Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php | 4 +++- Webservices/Endpoints/SentDate.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php b/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php index 5532c6485..a093767cd 100644 --- a/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php +++ b/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php @@ -213,7 +213,9 @@ private function checkByAddressData(OrderInterface $order) * which occurred since Magento 2.2.8/2.3.1. */ try { - return $this->magentoOrder->getShippingAddress($order->getOrderId()); + if ($order->getOrderId()) { + return $this->magentoOrder->getShippingAddress($order->getOrderId()); + } } catch (\Error $e) { if ($order->getQuoteId()) { return $address = $this->magentoOrder->getShippingAddress($order->getQuoteId(), 'quote'); diff --git a/Webservices/Endpoints/SentDate.php b/Webservices/Endpoints/SentDate.php index a84c58dfd..d933d027a 100644 --- a/Webservices/Endpoints/SentDate.php +++ b/Webservices/Endpoints/SentDate.php @@ -47,7 +47,7 @@ class SentDate extends AbstractEndpoint /** * @var string */ - private $version = 'v2_1'; + private $version = 'v2_2'; /** * @var string From c915e339a3c2e1841ad9cf57f5ab8a9a82dbc09d Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 4 Apr 2019 22:31:29 +0200 Subject: [PATCH 040/113] Put back setType() --- Webservices/Endpoints/Barcode.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Webservices/Endpoints/Barcode.php b/Webservices/Endpoints/Barcode.php index 101310adf..cd0db7dee 100644 --- a/Webservices/Endpoints/Barcode.php +++ b/Webservices/Endpoints/Barcode.php @@ -149,6 +149,14 @@ public function setCountryId($countryId) $this->countryId = $countryId; } + /** + * @param $type + */ + public function setType($type) + { + $this->type = $type; + } + /** * @param int $storeId */ From 718a9c3280c0e6c90830b57804bc7bb7f73c4d8c Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 5 Apr 2019 09:24:45 +0200 Subject: [PATCH 041/113] Fixed bugs after merge conflicts. --- Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php | 4 +++- Service/Handler/BarcodeHandler.php | 8 ++++++++ Service/Shipment/Barcode/Range.php | 7 +++++-- Webservices/Endpoints/Barcode.php | 7 ++++++- Webservices/Endpoints/Confirming.php | 12 +++++++----- Webservices/Endpoints/Labelling.php | 8 +++++--- Webservices/Endpoints/LabellingWithoutConfirm.php | 10 ++++++---- Webservices/Endpoints/TimeFrame.php | 6 ++++-- 8 files changed, 44 insertions(+), 18 deletions(-) diff --git a/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php b/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php index c69f62bff..100e19a1b 100644 --- a/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php +++ b/Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php @@ -216,7 +216,9 @@ private function checkByAddressData(OrderInterface $order) * which occurred since Magento 2.2.8/2.3.1. */ try { - return $this->magentoOrder->getShippingAddress($order->getOrderId()); + if ($order->getOrderId()) { + return $this->magentoOrder->getShippingAddress($order->getOrderId()); + } } catch (\Error $e) { if ($order->getQuoteId()) { return $address = $this->magentoOrder->getShippingAddress($order->getQuoteId(), 'quote'); diff --git a/Service/Handler/BarcodeHandler.php b/Service/Handler/BarcodeHandler.php index 56ff05b0f..0687b65b8 100644 --- a/Service/Handler/BarcodeHandler.php +++ b/Service/Handler/BarcodeHandler.php @@ -73,6 +73,11 @@ class BarcodeHandler */ private $countryId; + /** + * $var null|int + */ + private $storeId; + /** * @param BarcodeEndpoint $barcodeEndpoint * @param ShipmentRepositoryInterface $shipmentRepository @@ -107,6 +112,9 @@ public function prepareShipment($magentoShipmentId, $countryId) return; } + $magentoShipment = $shipment->getShipment(); + $this->storeId = $magentoShipment->getStoreId(); + $mainBarcode = $this->generate($shipment); $shipment->setMainBarcode($mainBarcode); $this->shipmentRepository->save($shipment); diff --git a/Service/Shipment/Barcode/Range.php b/Service/Shipment/Barcode/Range.php index 4f49a3e43..fee28571e 100644 --- a/Service/Shipment/Barcode/Range.php +++ b/Service/Shipment/Barcode/Range.php @@ -91,11 +91,12 @@ public function __construct( $this->globalpackConfiguration = $globalpack; $this->pepsConfiguration = $pepsConfiguration; } - + /** * @param $barcodeType * * @return array + * @throws \TIG\PostNL\Exception */ public function get($barcodeType) { @@ -128,9 +129,11 @@ public function getByCountryId($countryId, $storeId = null, $type = '') return $this->get('GLOBAL'); } - + /** * @param $type + * + * @throws \TIG\PostNL\Exception */ public function set($type) { diff --git a/Webservices/Endpoints/Barcode.php b/Webservices/Endpoints/Barcode.php index cd0db7dee..c7009b8c9 100644 --- a/Webservices/Endpoints/Barcode.php +++ b/Webservices/Endpoints/Barcode.php @@ -81,6 +81,11 @@ class Barcode extends AbstractEndpoint */ private $countryId; + /** + * @var string + */ + private $type = ''; + /** * Barcode constructor. * @@ -116,7 +121,7 @@ public function call() { $this->validateRequiredValues(); - $barcode = $this->barcodeRange->getByCountryId($this->countryId, $this->storeId); + $barcode = $this->barcodeRange->getByCountryId($this->countryId, $this->storeId, $this->type); $parameters = [ 'Message' => $this->message->get(''), diff --git a/Webservices/Endpoints/Confirming.php b/Webservices/Endpoints/Confirming.php index a63133bdc..801bcb28a 100644 --- a/Webservices/Endpoints/Confirming.php +++ b/Webservices/Endpoints/Confirming.php @@ -60,7 +60,7 @@ class Confirming extends AbstractEndpoint /** * @var string */ - private $version = 'v1_10'; + private $version = 'v2'; /** * @var string @@ -94,9 +94,11 @@ public function __construct( $shipmentData ); } - + /** - * {@inheritdoc} + * @return mixed + * @throws \Magento\Framework\Webapi\Exception + * @throws \TIG\PostNL\Webservices\Api\Exception */ public function call() { @@ -115,9 +117,9 @@ public function setParameters($shipment, $currentShipmentNumber = 1) 'Shipments' => $this->getShipments($shipment, $currentShipmentNumber), ]; } - + /** - * {@inheritdoc} + * @return string */ public function getLocation() { diff --git a/Webservices/Endpoints/Labelling.php b/Webservices/Endpoints/Labelling.php index a4b51a099..7156bf78a 100644 --- a/Webservices/Endpoints/Labelling.php +++ b/Webservices/Endpoints/Labelling.php @@ -60,7 +60,7 @@ class Labelling extends AbstractEndpoint /** * @var string */ - private $version = 'v2_1'; + private $version = 'v2_2'; /** * @var string @@ -96,7 +96,9 @@ public function __construct( } /** - * {@inheritdoc} + * @return mixed + * @throws \Magento\Framework\Webapi\Exception + * @throws \TIG\PostNL\Webservices\Api\Exception */ public function call() { @@ -125,7 +127,7 @@ public function setParameters($shipment, $currentShipmentNumber = 1) } /** - * {@inheritdoc} + * @return string */ public function getLocation() { diff --git a/Webservices/Endpoints/LabellingWithoutConfirm.php b/Webservices/Endpoints/LabellingWithoutConfirm.php index 1f402f49c..cdb4b5551 100644 --- a/Webservices/Endpoints/LabellingWithoutConfirm.php +++ b/Webservices/Endpoints/LabellingWithoutConfirm.php @@ -94,9 +94,11 @@ public function __construct( $shipmentData ); } - + /** - * {@inheritdoc} + * @return mixed + * @throws \Magento\Framework\Webapi\Exception + * @throws \TIG\PostNL\Webservices\Api\Exception */ public function call() { @@ -119,9 +121,9 @@ public function setParameters($shipment, $currentShipmentNumber = 1) 'Shipments' => $this->getShipments($shipment, $currentShipmentNumber), ]; } - + /** - * {@inheritdoc} + * @return string */ public function getLocation() { diff --git a/Webservices/Endpoints/TimeFrame.php b/Webservices/Endpoints/TimeFrame.php index 00efa4792..5787bb12c 100644 --- a/Webservices/Endpoints/TimeFrame.php +++ b/Webservices/Endpoints/TimeFrame.php @@ -109,12 +109,14 @@ public function __construct( $shipmentData ); } - + /** * @param bool $parseTimeFrames * - * @return mixed + * @return array|mixed + * @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Webapi\Exception + * @throws \TIG\PostNL\Webservices\Api\Exception */ public function call($parseTimeFrames = true) { From cd093b113dc3bac66a46c056d9cd9b7c792db6c6 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Fri, 5 Apr 2019 09:49:07 +0200 Subject: [PATCH 042/113] Too many properties according phpcs --- Service/Handler/BarcodeHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Service/Handler/BarcodeHandler.php b/Service/Handler/BarcodeHandler.php index 0687b65b8..364b2e87c 100644 --- a/Service/Handler/BarcodeHandler.php +++ b/Service/Handler/BarcodeHandler.php @@ -41,6 +41,7 @@ use \Magento\Framework\Exception\LocalizedException; use TIG\PostNL\Config\Provider\ProductOptions as ProductOptionsConfiguration; +// @codingStandardsIgnoreFile class BarcodeHandler { /** From 9241b094cf27eb6757d63c0b9d58a9ee81e9c47d Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 9 Apr 2019 09:06:55 +0200 Subject: [PATCH 043/113] POSTNLM2-789: Changed default value for Evening Delivery NL/BE to 'Deliver to stated address only'. --- etc/config.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/etc/config.xml b/etc/config.xml index a1ca545da..6b00e7565 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -102,13 +102,13 @@ - 3089 + 3385 1 2 - 4938 + 4941 0 2 @@ -143,6 +143,7 @@ #000000 40 code39 + code39 1 From 47ba2bd9b24bd230fe4f2efd88949d7b76fce003 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 9 Apr 2019 09:29:55 +0200 Subject: [PATCH 044/113] POSTNLM2-789: Removed accidental duplicated line. --- etc/config.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/etc/config.xml b/etc/config.xml index 6b00e7565..9275a947d 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -143,7 +143,6 @@ #000000 40 code39 - code39 1 From dce6ef5b4b697bd578620a9e496565e4dc13f93d Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 9 Apr 2019 09:41:46 +0200 Subject: [PATCH 045/113] POSTNLM2-788: Added default value '2' for PakjeGemak Express Fee --- etc/config.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/config.xml b/etc/config.xml index a1ca545da..44cfe195c 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -116,6 +116,7 @@ 1 0 + 2 3533 3543 From 97da72aebef86dbc4991684fe20ef6ff8cd46ef3 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 9 Apr 2019 11:42:24 +0200 Subject: [PATCH 046/113] POSTNLM2-790: Add check if module is disabled. --- Plugin/Postcodecheck/LayoutProcessor.php | 34 +++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Plugin/Postcodecheck/LayoutProcessor.php b/Plugin/Postcodecheck/LayoutProcessor.php index d9341f330..784bc0325 100644 --- a/Plugin/Postcodecheck/LayoutProcessor.php +++ b/Plugin/Postcodecheck/LayoutProcessor.php @@ -31,35 +31,51 @@ */ namespace TIG\PostNL\Plugin\Postcodecheck; -use TIG\PostNL\Plugin\Postcodecheck\Fields\Factory; -use TIG\PostNL\Config\Provider\Webshop; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; +use TIG\PostNL\Config\Provider\AccountConfiguration; +use TIG\PostNL\Config\Provider\Webshop; +use TIG\PostNL\Plugin\Postcodecheck\Fields\Factory; // @codingStandardsIgnoreFile class LayoutProcessor { /** - * @var Factory + * @var \TIG\PostNL\Plugin\Postcodecheck\Fields\Factory */ private $fieldFactory; - + + /** + * @var \TIG\PostNL\Config\Provider\AccountConfiguration + */ + private $accountConfig; + /** - * @var Webshop + * @var \TIG\PostNL\Config\Provider\Webshop */ private $webshopConfig; - + /** - * @var ScopeConfigInterface + * @var \Magento\Framework\App\Config\ScopeConfigInterface */ private $scopeConfig; - + + /** + * LayoutProcessor constructor. + * + * @param \TIG\PostNL\Plugin\Postcodecheck\Fields\Factory $factory + * @param \TIG\PostNL\Config\Provider\AccountConfiguration $accountConfig + * @param \TIG\PostNL\Config\Provider\Webshop $webshop + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + */ public function __construct( Factory $factory, + AccountConfiguration $accountConfig, Webshop $webshop, ScopeConfigInterface $scopeConfig ) { $this->fieldFactory = $factory; + $this->accountConfig = $accountConfig; $this->webshopConfig = $webshop; $this->scopeConfig = $scopeConfig; } @@ -72,7 +88,7 @@ public function __construct( */ public function afterProcess($subject, array $jsLayout) { - if (!$this->webshopConfig->getIsAddressCheckEnabled()) { + if (!$this->webshopConfig->getIsAddressCheckEnabled() || $this->accountConfig->isModusOff()) { return $jsLayout; } From 071c813acbc0266d68b56059146628d87a3ec115 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 9 Apr 2019 11:48:11 +0200 Subject: [PATCH 047/113] POSTNLM2-790: Don't use fully qualified class names in PHPDoc. --- Plugin/Postcodecheck/LayoutProcessor.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Plugin/Postcodecheck/LayoutProcessor.php b/Plugin/Postcodecheck/LayoutProcessor.php index 784bc0325..bc629f774 100644 --- a/Plugin/Postcodecheck/LayoutProcessor.php +++ b/Plugin/Postcodecheck/LayoutProcessor.php @@ -41,32 +41,32 @@ class LayoutProcessor { /** - * @var \TIG\PostNL\Plugin\Postcodecheck\Fields\Factory + * @var Factory */ private $fieldFactory; /** - * @var \TIG\PostNL\Config\Provider\AccountConfiguration + * @var AccountConfiguration */ private $accountConfig; /** - * @var \TIG\PostNL\Config\Provider\Webshop + * @var Webshop */ private $webshopConfig; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ private $scopeConfig; /** * LayoutProcessor constructor. * - * @param \TIG\PostNL\Plugin\Postcodecheck\Fields\Factory $factory - * @param \TIG\PostNL\Config\Provider\AccountConfiguration $accountConfig - * @param \TIG\PostNL\Config\Provider\Webshop $webshop - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param Factory $factory + * @param AccountConfiguration $accountConfig + * @param Webshop $webshop + * @param ScopeConfigInterface $scopeConfig */ public function __construct( Factory $factory, From 032c111483139771eaf9d4c9ebc6f8fd4bd6b2f8 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 16 Apr 2019 15:13:28 +0200 Subject: [PATCH 048/113] POSTNLM2-797: Removed default config values for test-credentials. --- etc/config.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/etc/config.xml b/etc/config.xml index d6de78a21..5f4c91c94 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -50,10 +50,6 @@ 2.1.0 - 2.1.16, 2.2.0 - 2.2.7, 2.3.0 - 2.3.1 0 - 11223344 - TOTA - GXRgqbUdNxL1xWLaGNR77cWeWWIGDSJw - 103861 From 5f89b32f95f8eb7d38dd589f15435b483e3793f4 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 16 Apr 2019 15:35:05 +0200 Subject: [PATCH 049/113] POSTNLM2-797: Removed Install-script, because it failed to fulfill its purpose. --- Setup/V110/Data/ApiKeyConfiguration.php | 92 ------------------------- etc/di.xml | 3 - 2 files changed, 95 deletions(-) delete mode 100644 Setup/V110/Data/ApiKeyConfiguration.php diff --git a/Setup/V110/Data/ApiKeyConfiguration.php b/Setup/V110/Data/ApiKeyConfiguration.php deleted file mode 100644 index 9d3a49ea3..000000000 --- a/Setup/V110/Data/ApiKeyConfiguration.php +++ /dev/null @@ -1,92 +0,0 @@ -scopeConfig = $scopeConfig; - $this->resourceConfig = $resourceConfig; - $this->encryptor = $encryptor; - } - - /** - * The api key is normally encrypted before it gets saved in the database. But for testing purposes we want to add - * a default API key in the test configuration. If we put this in the config.xml the system will try to decrypt - * an plain text value, resulting in an invalid api key. That's why we read the default value, encrypt it, and - * save it to the database. - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * - * @return void - */ - // @codingStandardsIgnoreLine - public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - $originalValue = $this->scopeConfig->getValue('tig_postnl/generalconfiguration_extension_status/api_key_test'); - $encryptedValue = $this->encryptor->encrypt($originalValue); - - $this->resourceConfig->saveConfig( - 'tig_postnl/generalconfiguration_extension_status/api_key_test', - $encryptedValue, - 'default', - 0 - ); - } -} diff --git a/etc/di.xml b/etc/di.xml index 5748c6767..b25f4c3a2 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -146,9 +146,6 @@ - - TIG\PostNL\Setup\V110\Data\ApiKeyConfiguration - TIG\PostNL\Setup\V120\Data\CustomProductAttributes From 06defd380c10100a877494e617abceef41db39a3 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 24 Apr 2019 10:08:27 +0200 Subject: [PATCH 050/113] POSTNLM2-771: Priority GlobalPack is now printed in A6 format with vertical orientation. --- Config/Source/OptionsAbstract.php | 2 +- Service/Shipment/Label/Type/AbstractType.php | 5 +- Service/Shipment/Label/Type/EPS.php | 71 +++++++++++++++-- Service/Shipment/Label/Type/GlobalPack.php | 81 +++++++++++++++++--- 4 files changed, 135 insertions(+), 24 deletions(-) diff --git a/Config/Source/OptionsAbstract.php b/Config/Source/OptionsAbstract.php index 68f259417..9e5ce07ad 100644 --- a/Config/Source/OptionsAbstract.php +++ b/Config/Source/OptionsAbstract.php @@ -596,7 +596,7 @@ abstract class OptionsAbstract 'countryLimitation' => false, 'group' => 'eps_package_options', ], - // PEPS Products + // Priority Products '6350' => [ 'value' => '6350', 'label' => 'Priority packets tracked', diff --git a/Service/Shipment/Label/Type/AbstractType.php b/Service/Shipment/Label/Type/AbstractType.php index 33d67f86d..395b8ea55 100644 --- a/Service/Shipment/Label/Type/AbstractType.php +++ b/Service/Shipment/Label/Type/AbstractType.php @@ -92,10 +92,9 @@ public function cleanup() } /** - * This function prevents that the fpdi->create() method is called multiple times. + * This function prevents that the $fpdi->create() method is called multiple times. */ - // @codingStandardsIgnoreLine - protected function createPdf() + public function createPdf() { if ($this->pdf) { return; diff --git a/Service/Shipment/Label/Type/EPS.php b/Service/Shipment/Label/Type/EPS.php index 9d451fdd1..f6865de7c 100644 --- a/Service/Shipment/Label/Type/EPS.php +++ b/Service/Shipment/Label/Type/EPS.php @@ -39,17 +39,29 @@ class EPS extends Domestic /** * These are combiLabel products, these codes are returned by PostNL in the label response (ProductCodeDelivery) */ - private $shouldRotate = [4940, 4950, 4983, 4985, 4986, 3622, 3642, 3659]; + private $rotated = [4940, 4950, 4983, 4985, 4986, 3622, 3642, 3659]; + + /** + * The product codes, returned by the label response, to alter label generation for priority products. + * + * @var array + */ + private $priority = [6350, 6550, 6940, 6942]; /** * @var bool */ - private $templateInserted = false; - + public $templateInserted = false; + /** * @param ShipmentLabelInterface $label * * @return \FPDF + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\Filter\FilterException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException + * @throws \setasign\Fpdi\PdfReader\PdfReaderException */ public function process(ShipmentLabelInterface $label) { @@ -58,8 +70,12 @@ public function process(ShipmentLabelInterface $label) $this->createPdf(); $this->pdf->AddPage('P', Fpdi::PAGE_SIZE_A6); $this->pdf->setSourceFile($filename); + + $productCode = $label->getProductCode(); - if ($this->isRotated() || in_array($label->getProductCode(), $this->shouldRotate)) { + if ($this->isRotated() + || ($this->isRotatedProduct($productCode) && !$this->isPriorityProduct($productCode)) + ) { $this->insertRotated(); } @@ -69,9 +85,27 @@ public function process(ShipmentLabelInterface $label) return $this->pdf; } - + + /** + * @param $code + * + * @return bool + */ + public function isRotatedProduct($code) + { + return in_array($code, $this->rotated); + } + /** - * This is a label that is standing, so rotate is before pasting. + * This is a label with a vertical orientation, so rotate it before inserting. + * + * @param bool $importPage + * + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\Filter\FilterException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException + * @throws \setasign\Fpdi\PdfReader\PdfReaderException */ private function insertRotated() { @@ -81,9 +115,15 @@ private function insertRotated() $this->pdf->useTemplate($pageId, - 130, 0); $this->pdf->Rotate(0); } - + /** * This is a default label, it does not need any modification. + * + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\Filter\FilterException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException + * @throws \setasign\Fpdi\PdfReader\PdfReaderException */ private function insertRegular() { @@ -91,9 +131,24 @@ private function insertRegular() $pageId = $this->pdf->importPage(1); $this->pdf->useTemplate($pageId, 0, 0, Fpdi::PAGE_SIZE_A6_WIDTH, Fpdi::PAGE_SIZE_A6_HEIGHT); } - + + /** + * @param $code + * + * @return bool + */ + public function isPriorityProduct($code) + { + return in_array($code, $this->priority); + } + /** * @return bool + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\Filter\FilterException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException + * @throws \setasign\Fpdi\PdfReader\PdfReaderException */ public function isRotated() { diff --git a/Service/Shipment/Label/Type/GlobalPack.php b/Service/Shipment/Label/Type/GlobalPack.php index a18ec4a83..ea1634046 100644 --- a/Service/Shipment/Label/Type/GlobalPack.php +++ b/Service/Shipment/Label/Type/GlobalPack.php @@ -29,32 +29,89 @@ * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ + namespace TIG\PostNL\Service\Shipment\Label\Type; use TIG\PostNL\Api\Data\ShipmentLabelInterface; +use TIG\PostNL\Service\Pdf\Fpdi; -class GlobalPack extends AbstractType implements TypeInterface +class GlobalPack extends EPS { /** * @param ShipmentLabelInterface $label * - * @return \TIG\PostNL\Service\Pdf\Fpdi + * @return \FPDF|mixed|\TIG\PostNL\Service\Pdf\Fpdi + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\Filter\FilterException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException + * @throws \setasign\Fpdi\PdfReader\PdfReaderException */ public function process(ShipmentLabelInterface $label) { - $filename = $this->saveTempLabel($label); - - $this->pdf = $this->fpdi->create(); + $filename = $this->saveTempLabel($label); + $productCode = $label->getProductCode(); + + $this->createPdf(); $count = $this->pdf->setSourceFile($filename); + for ($pageNo = 1; $pageNo <= $count; $pageNo++) { - $templateId = $this->pdf->importPage($pageNo); - $templateSize = $this->pdf->getTemplateSize($templateId); - $orientation = $templateSize['width'] > $templateSize['height'] ? 'L' :'P'; - - $this->pdf->AddPage($orientation, [$templateSize['width'], $templateSize['height']]); - $this->pdf->useTemplate($templateId); + if (!$this->isRotatedProduct($productCode) + && $this->isPriorityProduct($productCode) + ) { + $this->insertRotated($pageNo); + } + + if (!$this->templateInserted) { + $this->insertRegular($pageNo); + } } - + return $this->pdf; } + + /** + * Since Priority GP has its own resolution and size, we override this + * method. + * + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\Filter\FilterException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException + * @throws \setasign\Fpdi\PdfReader\PdfReaderException + */ + private function insertRotated($page) + { + $this->templateInserted = true; + $this->pdf->AddPage('P', Fpdi::PAGE_SIZE_A6); + + $pageId = $this->pdf->importPage($page); + + $this->pdf->Rotate(90); + $this->pdf->useTemplate($pageId, -130, 0, 150, 210); + $this->pdf->Rotate(0); + } + + /** + * This method is used for regular GlobalPack labels. + * + * @param $page + * + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\Filter\FilterException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException + * @throws \setasign\Fpdi\PdfReader\PdfReaderException + */ + private function insertRegular($page) + { + $this->templateInserted = true; + + $templateId = $this->pdf->importPage($page); + $templateSize = $this->pdf->getTemplateSize($templateId); + $orientation = $templateSize['width'] > $templateSize['height'] ? 'L' : 'P'; + + $this->pdf->AddPage($orientation, [$templateSize['width'], $templateSize['height']]); + $this->pdf->useTemplate($templateId, 0, 0, $templateSize['width'], $templateSize['height']); + } } From 3789fd13eeb0609cc68bd8e4d04b7736b0c0bc2c Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 24 Apr 2019 11:09:42 +0200 Subject: [PATCH 051/113] POSTNLM2-771: Moved Label Processing to separate method. Added getter and setter for templateInserted property. --- Service/Shipment/Label/Type/EPS.php | 24 ++++++++++--- Service/Shipment/Label/Type/GlobalPack.php | 39 +++++++++++++++------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Service/Shipment/Label/Type/EPS.php b/Service/Shipment/Label/Type/EPS.php index f6865de7c..d65c58db9 100644 --- a/Service/Shipment/Label/Type/EPS.php +++ b/Service/Shipment/Label/Type/EPS.php @@ -51,7 +51,7 @@ class EPS extends Domestic /** * @var bool */ - public $templateInserted = false; + private $templateInserted = false; /** * @param ShipmentLabelInterface $label @@ -79,7 +79,7 @@ public function process(ShipmentLabelInterface $label) $this->insertRotated(); } - if (!$this->templateInserted) { + if (!$this->getTemplateInserted()) { $this->insertRegular(); } @@ -109,7 +109,7 @@ public function isRotatedProduct($code) */ private function insertRotated() { - $this->templateInserted = true; + $this->setTemplateInserted(true); $pageId = $this->pdf->importPage(1); $this->pdf->Rotate(90); $this->pdf->useTemplate($pageId, - 130, 0); @@ -127,7 +127,7 @@ private function insertRotated() */ private function insertRegular() { - $this->templateInserted = true; + $this->setTemplateInserted(true); $pageId = $this->pdf->importPage(1); $this->pdf->useTemplate($pageId, 0, 0, Fpdi::PAGE_SIZE_A6_WIDTH, Fpdi::PAGE_SIZE_A6_HEIGHT); } @@ -161,4 +161,20 @@ public function isRotated() return false; } + + /** + * @param $value + */ + public function setTemplateInserted($value) + { + $this->templateInserted = $value; + } + + /** + * @return bool + */ + public function getTemplateInserted() + { + return $this->templateInserted; + } } diff --git a/Service/Shipment/Label/Type/GlobalPack.php b/Service/Shipment/Label/Type/GlobalPack.php index ea1634046..0a04a08df 100644 --- a/Service/Shipment/Label/Type/GlobalPack.php +++ b/Service/Shipment/Label/Type/GlobalPack.php @@ -40,7 +40,7 @@ class GlobalPack extends EPS /** * @param ShipmentLabelInterface $label * - * @return \FPDF|mixed|\TIG\PostNL\Service\Pdf\Fpdi + * @return \FPDF|Fpdi * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException * @throws \setasign\Fpdi\PdfParser\Filter\FilterException * @throws \setasign\Fpdi\PdfParser\PdfParserException @@ -56,20 +56,35 @@ public function process(ShipmentLabelInterface $label) $count = $this->pdf->setSourceFile($filename); for ($pageNo = 1; $pageNo <= $count; $pageNo++) { - if (!$this->isRotatedProduct($productCode) - && $this->isPriorityProduct($productCode) - ) { - $this->insertRotated($pageNo); - } - - if (!$this->templateInserted) { - $this->insertRegular($pageNo); - } + $this->processLabels($pageNo, $productCode); } return $this->pdf; } + /** + * @param $page + * @param $code + * + * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException + * @throws \setasign\Fpdi\PdfParser\Filter\FilterException + * @throws \setasign\Fpdi\PdfParser\PdfParserException + * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException + * @throws \setasign\Fpdi\PdfReader\PdfReaderException + */ + private function processLabels($page, $code) + { + if (!$this->isRotatedProduct($code) + && $this->isPriorityProduct($code) + ) { + $this->insertRotated($page); + } + + if (!$this->getTemplateInserted()) { + $this->insertRegular($page); + } + } + /** * Since Priority GP has its own resolution and size, we override this * method. @@ -82,7 +97,7 @@ public function process(ShipmentLabelInterface $label) */ private function insertRotated($page) { - $this->templateInserted = true; + $this->setTemplateInserted(true); $this->pdf->AddPage('P', Fpdi::PAGE_SIZE_A6); $pageId = $this->pdf->importPage($page); @@ -105,7 +120,7 @@ private function insertRotated($page) */ private function insertRegular($page) { - $this->templateInserted = true; + $this->setTemplateInserted(true); $templateId = $this->pdf->importPage($page); $templateSize = $this->pdf->getTemplateSize($templateId); From 220fbc569051d0d31718063372e12e0b452108ac Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 24 Apr 2019 13:31:13 +0200 Subject: [PATCH 052/113] POSTNLM2-771: Added 'shipment_country' column to tig_postnl_shipment table. --- Api/Data/ShipmentInterface.php | 19 +++++- Model/Shipment.php | 20 +++++++ .../Shipment/Labelling/GenerateAbstract.php | 21 +++++-- Setup/UpgradeSchema.php | 4 ++ .../V180/Schema/InstallPriorityAttribute.php | 58 +++++++++++++++++++ etc/di.xml | 3 + etc/module.xml | 2 +- 7 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 Setup/V180/Schema/InstallPriorityAttribute.php diff --git a/Api/Data/ShipmentInterface.php b/Api/Data/ShipmentInterface.php index c4389a6ba..44c75bf66 100644 --- a/Api/Data/ShipmentInterface.php +++ b/Api/Data/ShipmentInterface.php @@ -108,7 +108,19 @@ public function setShipmentType($value); * @return string|null */ public function getShipmentType(); - + + /** + * @param $value + * + * @return mixed + */ + public function setShipmentCountry($value); + + /** + * @return mixed + */ + public function getShipmentCountry(); + /** * @param $value * @@ -320,6 +332,11 @@ public function getOriginalShippingAddress(); * @return \Magento\Sales\Api\Data\ShipmentInterface */ public function getShipment(); + + /** + * @return mixed + */ + public function getShippingAddress(); /** * @return bool diff --git a/Model/Shipment.php b/Model/Shipment.php index ac07a0059..19c9f88dd 100644 --- a/Model/Shipment.php +++ b/Model/Shipment.php @@ -67,6 +67,8 @@ class Shipment extends AbstractModel implements ShipmentInterface, IdentityInter const FIELD_SHIPMENT_TYPE = 'shipment_type'; + const FIELD_SHIPMENT_COUNTRY = 'shipment_country'; + const FIELD_AC_CHARACTERISTIC = 'ac_characteristic'; const FIELD_AC_OPTION = 'ac_option'; @@ -445,6 +447,24 @@ public function getShipmentType() return $this->getData(static::FIELD_SHIPMENT_TYPE); } + /** + * @return string + */ + public function getShipmentCountry() + { + return $this->getData(static::FIELD_SHIPMENT_COUNTRY); + } + + /** + * @param $value + * + * @return \TIG\PostNL\Api\Data\ShipmentInterface + */ + public function setShipmentCountry($value) + { + return $this->setData(static::FIELD_SHIPMENT_COUNTRY, $value); + } + /** * @param $value * diff --git a/Service/Shipment/Labelling/GenerateAbstract.php b/Service/Shipment/Labelling/GenerateAbstract.php index 70bce000e..52eb246c1 100644 --- a/Service/Shipment/Labelling/GenerateAbstract.php +++ b/Service/Shipment/Labelling/GenerateAbstract.php @@ -114,16 +114,18 @@ public function getLabel(ShipmentInterface $shipment, $currentShipmentNumber, $c if ($responseShipments) { $this->saveDownpartnerData($shipment, $responseShipments); + $this->saveCountryId($shipment); } - $labelModels = $this->handleLabels($shipment, $responseShipments, $currentShipmentNumber); - if ($confirm) { $shipment->setConfirmedAt($this->date); $shipment->setConfirmed(true); - $this->shipmentRepository->save($shipment); } + $labelModels = $this->handleLabels($shipment, $responseShipments, $currentShipmentNumber); + + $this->shipmentRepository->save($shipment); + return $labelModels; } @@ -140,7 +142,17 @@ private function saveDownpartnerData(ShipmentInterface $shipment, $response) $shipment->setDownpartnerBarcode($downPartnerBarcode); $shipment->setDownpartnerId($downPartnerId); $shipment->setDownpartnerLocation($downPartnerLocation); - $this->shipmentRepository->save($shipment); + } + + /** + * @param ShipmentInterface $shipment + */ + private function saveCountryId(ShipmentInterface $shipment) + { + $shippingAddress = $shipment->getShippingAddress(); + $countryId = $shippingAddress->getCountryId(); + + $shipment->setShipmentCountry($countryId); } /** @@ -221,7 +233,6 @@ private function getLabelModels($labelItem, ShipmentInterface $shipment, $curren */ if ($labelItem->ProductCodeDelivery !== $shipment->getProductCode()) { $shipment->setProductCode($labelItem->ProductCodeDelivery); - $this->shipmentRepository->save($shipment); } return $labelModels; diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index aaf31410e..90474814f 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -86,6 +86,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con if (version_compare($context->getVersion(), '1.7.4', '<')) { $this->upgradeSchemas($this->upgradeSchemaObjects['v1.7.4'], $setup, $context); } + + if (version_compare($context->getVersion(), '1.8.0', '<')) { + $this->upgradeSchemas($this->upgradeSchemaObjects['v1.8.0'], $setup, $context); + } $setup->endSetup(); } diff --git a/Setup/V180/Schema/InstallPriorityAttribute.php b/Setup/V180/Schema/InstallPriorityAttribute.php new file mode 100644 index 000000000..dc537a986 --- /dev/null +++ b/Setup/V180/Schema/InstallPriorityAttribute.php @@ -0,0 +1,58 @@ + \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, + 'length' => 12, + 'nullable' => true, + 'default' => null, + 'comment' => 'Country', + 'after' => 'shipment_type' + ]; + } +} diff --git a/etc/di.xml b/etc/di.xml index b25f4c3a2..c26da29e6 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -105,6 +105,9 @@ + + TIG\PostNL\Setup\V180\Schema\InstallPriorityAttribute + TIG\PostNL\Setup\V174\Schema\InstallDownpartnerAttributes diff --git a/etc/module.xml b/etc/module.xml index 285b7be1a..68682a8ad 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -32,7 +32,7 @@ * --> - + From 7bb151de763fab246dbecd7fa93acdb9c38f5bcc Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 24 Apr 2019 14:49:08 +0200 Subject: [PATCH 053/113] POSTNLM2-771: Priority GP labels to US are now excluded from Rotation. --- Service/Shipment/Label/Type/GlobalPack.php | 49 +++++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/Service/Shipment/Label/Type/GlobalPack.php b/Service/Shipment/Label/Type/GlobalPack.php index 0a04a08df..e6cd3e075 100644 --- a/Service/Shipment/Label/Type/GlobalPack.php +++ b/Service/Shipment/Label/Type/GlobalPack.php @@ -32,11 +32,19 @@ namespace TIG\PostNL\Service\Shipment\Label\Type; +use TIG\PostNL\Api\Data\ShipmentInterface; use TIG\PostNL\Api\Data\ShipmentLabelInterface; use TIG\PostNL\Service\Pdf\Fpdi; class GlobalPack extends EPS { + /** + * The labels of these Priority GP countries are not supposed to be rotated. + * + * @var array + */ + private $excludedCountries = ["US"]; + /** * @param ShipmentLabelInterface $label * @@ -49,22 +57,24 @@ class GlobalPack extends EPS */ public function process(ShipmentLabelInterface $label) { - $filename = $this->saveTempLabel($label); $productCode = $label->getProductCode(); + $shipment = $label->getShipment(); + $filename = $this->saveTempLabel($label); $this->createPdf(); $count = $this->pdf->setSourceFile($filename); for ($pageNo = 1; $pageNo <= $count; $pageNo++) { - $this->processLabels($pageNo, $productCode); + $this->processLabels($shipment, $pageNo, $productCode); } return $this->pdf; } /** - * @param $page - * @param $code + * @param ShipmentInterface $shipment + * @param $page + * @param $code * * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException * @throws \setasign\Fpdi\PdfParser\Filter\FilterException @@ -72,19 +82,30 @@ public function process(ShipmentLabelInterface $label) * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException * @throws \setasign\Fpdi\PdfReader\PdfReaderException */ - private function processLabels($page, $code) + private function processLabels(ShipmentInterface $shipment, $page, $code) { if (!$this->isRotatedProduct($code) && $this->isPriorityProduct($code) ) { - $this->insertRotated($page); + $countryId = $shipment->getShipmentCountry(); + $this->insertRotated($page, $countryId); } - + if (!$this->getTemplateInserted()) { $this->insertRegular($page); } } + /** + * @param $country string + * + * @return bool + */ + private function isExcludedCountry($country) + { + return in_array($country, $this->excludedCountries); + } + /** * Since Priority GP has its own resolution and size, we override this * method. @@ -95,16 +116,22 @@ private function processLabels($page, $code) * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException * @throws \setasign\Fpdi\PdfReader\PdfReaderException */ - private function insertRotated($page) + private function insertRotated($page, $countryId) { $this->setTemplateInserted(true); $this->pdf->AddPage('P', Fpdi::PAGE_SIZE_A6); $pageId = $this->pdf->importPage($page); - $this->pdf->Rotate(90); - $this->pdf->useTemplate($pageId, -130, 0, 150, 210); - $this->pdf->Rotate(0); + if (!$this->isExcludedCountry($countryId)) { + $this->pdf->Rotate(90); + $this->pdf->useTemplate($pageId, -130, 0, 150, 210); + $this->pdf->Rotate(0); + + return; + } + + $this->pdf->useTemplate($pageId, 0, 0, 103, 150); } /** From 6b56ac886e34c1b9f268021af85ba223ce08194b Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 24 Apr 2019 15:48:16 +0200 Subject: [PATCH 054/113] POSTNLM2-796: Fixed link according to issue. --- etc/adminhtml/system/postnlsettings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/adminhtml/system/postnlsettings.xml b/etc/adminhtml/system/postnlsettings.xml index 28ddd489d..d4dff4b20 100644 --- a/etc/adminhtml/system/postnlsettings.xml +++ b/etc/adminhtml/system/postnlsettings.xml @@ -86,7 +86,7 @@ TIG\PostNL\Block\Adminhtml\Config\Form\Field\Fieldset tig_postnl-sub-section - PostNL product options.]]> + PostNL product options.]]> From 83de290d2c544ae9cc7ae0018242973668f0f1d1 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 24 Apr 2019 16:10:37 +0200 Subject: [PATCH 055/113] POSTNLM2-796: Replace with Tiny URL --- etc/adminhtml/system/postnlsettings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/adminhtml/system/postnlsettings.xml b/etc/adminhtml/system/postnlsettings.xml index d4dff4b20..4c5f36c55 100644 --- a/etc/adminhtml/system/postnlsettings.xml +++ b/etc/adminhtml/system/postnlsettings.xml @@ -86,7 +86,7 @@ TIG\PostNL\Block\Adminhtml\Config\Form\Field\Fieldset tig_postnl-sub-section - PostNL product options.]]> + PostNL product options.]]> From d201eb8d3bc8234924beb5c41fa2b22509b2b53a Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 25 Apr 2019 12:54:46 +0200 Subject: [PATCH 056/113] POSTNLM2-771: Added Unit-tests for new functions. --- Service/Shipment/Label/Type/GlobalPack.php | 2 +- .../Service/Shipment/Label/Type/EPSTest.php | 68 +++++++++++++++++++ .../Shipment/Label/Type/GlobalPackTest.php | 55 +++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 Test/Unit/Service/Shipment/Label/Type/EPSTest.php create mode 100644 Test/Unit/Service/Shipment/Label/Type/GlobalPackTest.php diff --git a/Service/Shipment/Label/Type/GlobalPack.php b/Service/Shipment/Label/Type/GlobalPack.php index e6cd3e075..3bf5e623b 100644 --- a/Service/Shipment/Label/Type/GlobalPack.php +++ b/Service/Shipment/Label/Type/GlobalPack.php @@ -101,7 +101,7 @@ private function processLabels(ShipmentInterface $shipment, $page, $code) * * @return bool */ - private function isExcludedCountry($country) + public function isExcludedCountry($country) { return in_array($country, $this->excludedCountries); } diff --git a/Test/Unit/Service/Shipment/Label/Type/EPSTest.php b/Test/Unit/Service/Shipment/Label/Type/EPSTest.php new file mode 100644 index 000000000..44898e340 --- /dev/null +++ b/Test/Unit/Service/Shipment/Label/Type/EPSTest.php @@ -0,0 +1,68 @@ +getInstance(); + $result = $instance->isPriorityProduct(6350); + $expected = true; + + $this->assertEquals($expected, $result); + } + + /** + * @throws \Exception + */ + public function testIsRotatedProduct() + { + /** @var EPS $instance */ + $instance = $this->getInstance(); + $result = $instance->isRotatedProduct(4940); + $expected = true; + + $this->assertEquals($expected, $result); + } +} diff --git a/Test/Unit/Service/Shipment/Label/Type/GlobalPackTest.php b/Test/Unit/Service/Shipment/Label/Type/GlobalPackTest.php new file mode 100644 index 000000000..2a8f45528 --- /dev/null +++ b/Test/Unit/Service/Shipment/Label/Type/GlobalPackTest.php @@ -0,0 +1,55 @@ +getInstance(); + $result = $instance->isExcludedCountry("US"); + $expected = true; + + $this->assertEquals($expected, $result); + } +} From d074c6db206f23af148aa83213d64e774752f835 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Mon, 29 Apr 2019 15:46:46 +0200 Subject: [PATCH 057/113] GITHUB-108/POSTNLM2-809: Added fix suggested by @simonjanguapa. --- view/frontend/web/js/Helper/State.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/view/frontend/web/js/Helper/State.js b/view/frontend/web/js/Helper/State.js index e8ca26e97..f78611b8a 100644 --- a/view/frontend/web/js/Helper/State.js +++ b/view/frontend/web/js/Helper/State.js @@ -57,6 +57,10 @@ define([ return; } + if (shippingMethod.carrier_code !== 'tig_postnl') { + currentSelectedShipmentType(shippingMethod.carrier_code); + } + if (shippingMethod.carrier_code === 'tig_postnl') { return; } From c22ce28debd441e3df0e9259c44f3a7ba7413067 Mon Sep 17 00:00:00 2001 From: Dennis van der Hammen Date: Tue, 30 Apr 2019 11:21:48 +0200 Subject: [PATCH 058/113] POSTNLM2-808 - Fixed an issue when freeMethodWeight returned null, showing the wrong tablerate --- Service/Carrier/Price/Calculator.php | 2 +- Service/Carrier/Price/Tablerate.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Service/Carrier/Price/Calculator.php b/Service/Carrier/Price/Calculator.php index a96e3eb06..cf17ed712 100644 --- a/Service/Carrier/Price/Calculator.php +++ b/Service/Carrier/Price/Calculator.php @@ -177,7 +177,7 @@ private function getTableratePrice(RateRequest $request) return [ 'price' => $ratePrice['price'], - 'cost' => $ratePrice['cost'], + 'cost' => $ratePrice['price'], ]; } diff --git a/Service/Carrier/Price/Tablerate.php b/Service/Carrier/Price/Tablerate.php index 0cb2c2399..e505c6eac 100644 --- a/Service/Carrier/Price/Tablerate.php +++ b/Service/Carrier/Price/Tablerate.php @@ -52,6 +52,7 @@ class Tablerate /** * @param TablerateFactory $tablerateFactory * @param GetFreeBoxes $getFreeBoxes + * @param CheckoutSession $checkoutSession */ public function __construct( TablerateFactory $tablerateFactory, @@ -171,7 +172,7 @@ private function getRate(RateRequest $request) $oldWeight = $request->getPackageWeight(); $oldQty = $request->getPackageQty(); - $request->setPackageWeight($request->getFreeMethodWeight()); + $request->setPackageWeight($request->getFreeMethodWeight() ?: $oldWeight); $request->setPackageQty($oldQty - $this->getFreeBoxes->get($request)); /** @var TablerateModel $tablerate */ From 1a124efa81a7f9b6c9fddcb7ff88a0f5b238949b Mon Sep 17 00:00:00 2001 From: Dennis van der Hammen Date: Tue, 30 Apr 2019 11:29:50 +0200 Subject: [PATCH 059/113] Removed unused phpdocs --- Service/Carrier/Price/Tablerate.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Service/Carrier/Price/Tablerate.php b/Service/Carrier/Price/Tablerate.php index e505c6eac..3353d69b7 100644 --- a/Service/Carrier/Price/Tablerate.php +++ b/Service/Carrier/Price/Tablerate.php @@ -52,7 +52,6 @@ class Tablerate /** * @param TablerateFactory $tablerateFactory * @param GetFreeBoxes $getFreeBoxes - * @param CheckoutSession $checkoutSession */ public function __construct( TablerateFactory $tablerateFactory, From 5fe05c7b2bb7ebf6c560977f91e68d6dd8ecd243 Mon Sep 17 00:00:00 2001 From: Dennis van der Hammen Date: Tue, 30 Apr 2019 14:12:04 +0200 Subject: [PATCH 060/113] POSTNLM2-801 - Allow installation of older zend-barcode versions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b57fc5a60..2e716462a 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "ext-soap": "*", "magento/framework": ">=100.1.0,<=100.1.17|>=101.0.0,<=101.0.8|>=102.0.0,<=102.0.1", "setasign/fpdi-fpdf": "2.1", - "zendframework/zend-barcode" : "2.7" + "zendframework/zend-barcode" : "2.5.2|2.7" }, "type": "magento2-module", "license": "CC-BY-NC-ND-3.0", From 4b1ddfeb70c20bb7563c66d97a4b99c917d349a6 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 1 May 2019 08:37:20 +0200 Subject: [PATCH 061/113] POSTNLM2-771: Added non-blocking notice for Priority Parcels and fixed some typo's. [needs further testing!] --- Config/Provider/ShippingOptions.php | 2 +- Config/Source/Options/DefaultOptions.php | 6 +- Controller/Adminhtml/LabelAbstract.php | 7 +- .../Shipment/ConfirmAndPrintShippingLabel.php | 3 +- .../Adminhtml/Shipment/ConfirmShipping.php | 4 +- .../Adminhtml/Shipment/PrintShippingLabel.php | 3 +- Service/Shipment/Label/Generate.php | 11 ++- Service/Shipment/Label/Validator.php | 77 ++++++++++--------- Service/Shipment/Labelling/GetLabels.php | 8 +- i18n/en_US.csv | 1 + i18n/nl_NL.csv | 1 + 11 files changed, 64 insertions(+), 59 deletions(-) diff --git a/Config/Provider/ShippingOptions.php b/Config/Provider/ShippingOptions.php index 481c67cd6..f5b9c0499 100644 --- a/Config/Provider/ShippingOptions.php +++ b/Config/Provider/ShippingOptions.php @@ -247,7 +247,7 @@ public function canUseEpsBusinessProducts() /** * @return bool */ - public function canUsePepsProducts() + public function canUsePriority() { return (bool) $this->getConfigFromXpath(static::XPATH_SHIPPING_OPTIONS_PEPS_ACTIVE); } diff --git a/Config/Source/Options/DefaultOptions.php b/Config/Source/Options/DefaultOptions.php index 88a041618..8d64a893d 100644 --- a/Config/Source/Options/DefaultOptions.php +++ b/Config/Source/Options/DefaultOptions.php @@ -92,7 +92,7 @@ public function toOptionArray() */ public function getBeProducts() { - $beProducts[] = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; + $beProducts[] = $this->shippingOptions->canUsePriority() ? $this->productOptions->getPriorityOptions() : []; $beProducts[] = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; $beProducts[] = $this->shippingOptions->canUseCargoProducts() ? $this->productOptions->getCargoOptions() : []; $beProducts[] = $this->productOptions->getEuOptions(); @@ -105,7 +105,7 @@ public function getBeProducts() */ public function getEpsProducts() { - $epsProducts[] = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; + $epsProducts[] = $this->shippingOptions->canUsePriority() ? $this->productOptions->getPriorityOptions() : []; $epsProducts[] = $this->shippingOptions->canUseEpsBusinessProducts() ? $this->productOptions->getEpsBusinessOptions() : []; $epsProducts[] = $this->productOptions->getEpsOptions(); @@ -117,7 +117,7 @@ public function getEpsProducts() */ public function getGlobalProducts() { - $globalProducts[] = $this->shippingOptions->canUsePepsProducts() ? $this->productOptions->getPriorityOptions() : []; + $globalProducts[] = $this->shippingOptions->canUsePriority() ? $this->productOptions->getPriorityOptions() : []; $globalProducts[] = $this->productOptions->getGlobalPackOptions(); return call_user_func_array("array_merge", $globalProducts); diff --git a/Controller/Adminhtml/LabelAbstract.php b/Controller/Adminhtml/LabelAbstract.php index dd7a048a9..a5879b09b 100644 --- a/Controller/Adminhtml/LabelAbstract.php +++ b/Controller/Adminhtml/LabelAbstract.php @@ -119,8 +119,7 @@ protected function setLabel($shipmentId) { $labels = $this->getLabels->get($shipmentId); if (isset($labels['errors'])) { - $this->handelRequestErrors($labels['errors']); - return; + $this->handleRequestErrors($labels['errors']); } if (empty($labels)) { @@ -140,7 +139,7 @@ protected function setPackingslip($shipmentId, $withLabels = true, $confirm = tr { $packingslip = $this->getPackingSlip->get($shipmentId, $withLabels, $confirm); if (is_array($packingslip) && isset($packingslip['errors'])) { - $this->handelRequestErrors($packingslip['errors']); + $this->handleRequestErrors($packingslip['errors']); return; } @@ -166,7 +165,7 @@ protected function setTracks($shipment) * @param $errors */ //@codingStandardsIgnoreLine - protected function handelRequestErrors($errors) + protected function handleRequestErrors($errors) { foreach ($errors as $error) { $this->messageManager->addWarningMessage($error); diff --git a/Controller/Adminhtml/Shipment/ConfirmAndPrintShippingLabel.php b/Controller/Adminhtml/Shipment/ConfirmAndPrintShippingLabel.php index f0e5aabf0..9751b57c7 100644 --- a/Controller/Adminhtml/Shipment/ConfirmAndPrintShippingLabel.php +++ b/Controller/Adminhtml/Shipment/ConfirmAndPrintShippingLabel.php @@ -94,8 +94,7 @@ public function execute() { $labels = $this->getLabels(); if (isset($labels['errors'])) { - $this->handelRequestErrors($labels['errors']); - return $this->_redirect($this->_redirect->getRefererUrl()); + $this->handleRequestErrors($labels['errors']); } if (empty($labels)) { diff --git a/Controller/Adminhtml/Shipment/ConfirmShipping.php b/Controller/Adminhtml/Shipment/ConfirmShipping.php index 70c39f563..083764cd9 100644 --- a/Controller/Adminhtml/Shipment/ConfirmShipping.php +++ b/Controller/Adminhtml/Shipment/ConfirmShipping.php @@ -104,7 +104,7 @@ public function execute() $this->setConfirmedAt($shipmentId); $this->setTrack($shipmentId); - $this->messageManager->addComplexSuccessMessage( + $this->messageManager->addSuccessMessage( // @codingStandardsIgnoreLine __('Shipment successfully confirmed')->getText() ); @@ -123,7 +123,7 @@ private function confirm() } catch (Exception $exception) { $this->messageManager->addErrorMessage( // @codingStandardsIgnoreLine - __('Could not confirm shipment : %1', $exception->getLogMessage())->getText() + __('Could not confirm shipment: %1', $exception->getLogMessage())->getText() ); return $this->_redirect($this->_redirect->getRefererUrl()); } diff --git a/Controller/Adminhtml/Shipment/PrintShippingLabel.php b/Controller/Adminhtml/Shipment/PrintShippingLabel.php index d93f54634..9a76fe3d1 100644 --- a/Controller/Adminhtml/Shipment/PrintShippingLabel.php +++ b/Controller/Adminhtml/Shipment/PrintShippingLabel.php @@ -86,8 +86,7 @@ public function execute() { $labels = $this->getLabels(); if (isset($labels['errors'])) { - $this->handelRequestErrors($labels['errors']); - return $this->_redirect($this->_redirect->getRefererUrl()); + $this->handleRequestErrors($labels['errors']); } if (empty($labels)) { diff --git a/Service/Shipment/Label/Generate.php b/Service/Shipment/Label/Generate.php index 3ab90eae1..490407f7b 100644 --- a/Service/Shipment/Label/Generate.php +++ b/Service/Shipment/Label/Generate.php @@ -45,7 +45,10 @@ class Generate * @var Merge */ private $merge; - + + /** + * @var array + */ private $globalPackLabels = []; /** @@ -91,12 +94,14 @@ public function run(array $labels, $createNewPdf = false) public function orderLabels($labels) { $otherLabels = array_filter($labels, function ($label) { - /** @var ShipmentLabelInterface $label */ + /** @var array|ShipmentLabelInterface $label */ + if (is_array($label)) { + return false; + } if (strtoupper($label->getType()) == ProductInfo::SHIPMENT_TYPE_GP) { $this->globalPackLabels[] = $label; return false; } - return true; }); diff --git a/Service/Shipment/Label/Validator.php b/Service/Shipment/Label/Validator.php index b24662a50..288d373cd 100644 --- a/Service/Shipment/Label/Validator.php +++ b/Service/Shipment/Label/Validator.php @@ -84,21 +84,30 @@ public function validate($input) return array_values($filtered); } - + /** - * @param ShipmentInterface $shipment + * @param ShipmentLabelInterface|null $model * * @return bool */ - public function canRequest(ShipmentInterface $shipment) + private function filterInput(ShipmentLabelInterface $model = null) { - if ($shipment->isGlobalPack()) { - return $this->validateGlobalPack($shipment); + if ($model === null) { + return false; } - - return $this->validateProductCode($shipment); + + $label = $model->getLabel(); + + if (!is_string($label) || empty($label)) { + return false; + } + + $start = substr($label, 0, strlen('invalid')); + $start = strtolower($start); + + return $start != 'invalid'; } - + /** * @return array */ @@ -106,7 +115,21 @@ public function getErrors() { return $this->errors; } + + /** + * @param ShipmentInterface $shipment + * + * @return bool + */ + public function validateProduct(ShipmentInterface $shipment) + { + if ($shipment->isGlobalPack()) { + return $this->validateGlobalPack($shipment); + } + return $this->validatePriority($shipment); + } + /** * @param $shipment * @@ -121,54 +144,32 @@ private function validateGlobalPack(ShipmentInterface $shipment) return false; } - return $this->validateProductCode($shipment); + return $this->validatePriority($shipment); } - + /** * @param $shipment * * @return bool */ - private function validateProductCode(ShipmentInterface $shipment) + private function validatePriority(ShipmentInterface $shipment) { $code = $shipment->getProductCode(); - $isPeps = $this->productOptions->checkProductByFlags($code, 'group', 'priority_options'); + $isPriority = $this->productOptions->checkProductByFlags($code, 'group', 'priority_options'); - if ($isPeps && !$this->shippingOptions->canUsePepsProducts()) { + if ($isPriority && !$this->shippingOptions->canUsePriority()) { $magentoShipment = $shipment->getShipment(); // @codingStandardsIgnoreLine $this->errors[] = __('Could not print labels for shipment %1. Priority Delivery is disabled. Please contact your PostNL account manager before you enable this method.', $magentoShipment->getIncrementId()); return false; } - if ($isPeps && $shipment->getParcelCount() < 5) { + /** We want to show this notification for every Priority Shipment */ + if ($isPriority) { // @codingStandardsIgnoreLine - $this->errors[] = __('A Priority Delivery requires a minimum of 5 parcels/packages.'); + $this->errors[] = __('Tracked Parcels can only be used if 5 packages or more are delivered in a domestic mail bag with an attached bag label specific for priority parcels.'); } return true; } - - /** - * @param ShipmentLabelInterface|null $model - * - * @return bool - */ - private function filterInput(ShipmentLabelInterface $model = null) - { - if ($model === null) { - return false; - } - - $label = $model->getLabel(); - - if (!is_string($label) || empty($label)) { - return false; - } - - $start = substr($label, 0, strlen('invalid')); - $start = strtolower($start); - - return $start != 'invalid'; - } } diff --git a/Service/Shipment/Labelling/GetLabels.php b/Service/Shipment/Labelling/GetLabels.php index de5108635..22de267e1 100644 --- a/Service/Shipment/Labelling/GetLabels.php +++ b/Service/Shipment/Labelling/GetLabels.php @@ -99,12 +99,12 @@ public function get($shipmentId, $confirm = true) return []; } - if (!$this->labelValidator->canRequest($shipment)) { - return ['errors' => $this->labelValidator->getErrors()]; - } - + /** Validate products and generate error/warning messages */ + $this->labelValidator->validateProduct($shipment); + $labels = $this->getLabels($shipment, $confirm); $labels = $this->labelValidator->validate($labels); + $labels['errors'] = $this->labelValidator->getErrors(); return $labels; } diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 1d5797272..a86531072 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -416,3 +416,4 @@ Percent,Percent "Maximum weight per parcel","Maximum weight per parcel" "Defines the maximum weight per parcel. Uses the Weight Unit as defined in: General > General > Local Options > Weight Unit","Defines the maximum weight per parcel. Uses the Weight Unit as defined in: General > General > Local Options > Weight Unit" "If the total weight of the order exceeds the value defined here, it will be divided into multiple parcels. A separate label will be generated for each parcel.","If the total weight of the order exceeds the value defined here, it will be divided into multiple parcels. A separate label will be generated for each parcel." +"Packets Tracked can only be used if 5 packages or more are delivered in a domestic mail bag with an attached bag label specific for priority parcels.","Packets Tracked can only be used if 5 packages or more are delivered in a domestic mail bag with an attached bag label specific for priority parcels." diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index 5d8716c33..885ab0247 100644 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -436,3 +436,4 @@ Percent,Percentage "Maximum weight per parcel","Maximaal gewicht per pakket" "Defines the maximum weight per parcel. Uses the Weight Unit as defined in: General > General > Local Options > Weight Unit","Bepaald het maximale gewicht per pakket. Gebruikt de eenheid, zoals ingesteld onder Algemeen > Algemeen > Lokalisatie-opties > Gewichtseenheid" "If the total weight of the order exceeds the value defined here, it will be divided into multiple parcels. A separate label will be generated for each parcel.","Als het totale gewicht deze waarde overschrijdt, zal de bestelling opgedeeld worden in meerdere pakketten. Voor ieder pakket zal een apart label worden gegenereerd." +"Packets Tracked can only be used if 5 packages or more are delivered in a domestic mail bag with an attached bag label specific for priority parcels.","Pakjes Tracked kunnen alleen gebruikt worden als 5 pakketten of meer aangeleverd worden in een binnenlandse postzak met een aangehecht zaklabel specifiek voor Priority Parcels." \ No newline at end of file From 970b470475cc7dce1042127e67969679dd2cc449 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 1 May 2019 14:55:36 +0200 Subject: [PATCH 062/113] POSTNLM2-795: Added 'fallback' order-type and PostNL\DeliveryOptions\Save-controller should always be triggered. --- Controller/DeliveryOptions/Save.php | 3 +- Controller/DeliveryOptions/Timeframes.php | 4 +- Helper/DeliveryOptions/OrderParams.php | 101 ++++++++++-------- .../js/Renderer/DeliveryOptions/Delivery.js | 15 ++- 4 files changed, 70 insertions(+), 53 deletions(-) diff --git a/Controller/DeliveryOptions/Save.php b/Controller/DeliveryOptions/Save.php index 0b4050872..54365edca 100644 --- a/Controller/DeliveryOptions/Save.php +++ b/Controller/DeliveryOptions/Save.php @@ -146,7 +146,8 @@ private function saveDeliveryOption($params) */ private function addSessionDataToParams($params) { - if (!isset($params['date']) && $params['type'] == 'pickup') { + if (!isset($params['date']) && $params['type'] == 'pickup' + || !isset($params['date']) && $params['type'] == 'fallback') { $params['date'] = $this->checkoutSession->getPostNLDeliveryDate(); } diff --git a/Controller/DeliveryOptions/Timeframes.php b/Controller/DeliveryOptions/Timeframes.php index 6f978a9a8..2b82b7be7 100644 --- a/Controller/DeliveryOptions/Timeframes.php +++ b/Controller/DeliveryOptions/Timeframes.php @@ -132,7 +132,7 @@ public function execute() * * @return array|\Magento\Framework\Phrase */ - private function getPosibleDeliveryDays($address) + private function getPossibleDeliveryDays($address) { $startDate = $this->getDeliveryDay($address); @@ -158,7 +158,7 @@ private function getValidResponeType($price) return [ 'price' => $price, - 'timeframes' => $this->getPosibleDeliveryDays($address) + 'timeframes' => $this->getPossibleDeliveryDays($address) ]; } diff --git a/Helper/DeliveryOptions/OrderParams.php b/Helper/DeliveryOptions/OrderParams.php index 7a323acb8..636b49386 100644 --- a/Helper/DeliveryOptions/OrderParams.php +++ b/Helper/DeliveryOptions/OrderParams.php @@ -29,6 +29,7 @@ * @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ + namespace TIG\PostNL\Helper\DeliveryOptions; use TIG\PostNL\Exception as PostnlException; @@ -40,57 +41,65 @@ class OrderParams { private $optionParams = [ 'quote_id' => [ - 'pickup' => true, - 'delivery' => true + 'pickup' => true, + 'delivery' => true, + 'fallback' => false ], 'delivery_date' => [ - 'pickup' => true, - 'delivery' => true + 'pickup' => true, + 'delivery' => true, + 'fallback' => true ], 'expected_delivery_time_start' => [ - 'pickup' => false, - 'delivery' => true + 'pickup' => false, + 'delivery' => true, + 'fallback' => false ], 'expected_delivery_time_end' => [ - 'pickup' => false, - 'delivery' => true + 'pickup' => false, + 'delivery' => true, + 'fallback' => false ], 'is_pakjegemak' => [ - 'pickup' => true, - 'delivery' => false + 'pickup' => true, + 'delivery' => false, + 'fallback' => false ], 'pg_location_code' => [ - 'pickup' => true, - 'delivery' => false + 'pickup' => true, + 'delivery' => false, + 'fallback' => false ], 'pg_retail_network_id' => [ - 'pickup' => true, - 'delivery' => false + 'pickup' => true, + 'delivery' => false, + 'fallback' => false ], 'pg_address' => [ - 'pickup' => true, - 'delivery' => false + 'pickup' => true, + 'delivery' => false, + 'fallback' => false ] ]; /** * @var FeeCalculator */ private $feeCalculator; - + /** * @var ProductCodeAndType */ private $productCodeAndType; - + /** * @var ProductOptions */ private $productOptions; - + /** * @param FeeCalculator $feeCalculator * @param ProductCodeAndType $productCodeAndType - * @param ProductOptions $productOptions + * @param ProductOptions $productOptions */ public function __construct( FeeCalculator $feeCalculator, @@ -101,7 +110,7 @@ public function __construct( $this->productCodeAndType = $productCodeAndType; $this->productOptions = $productOptions; } - + /** * @param $params * @@ -114,19 +123,19 @@ public function get($params) $params = $this->formatParamData($params); $params = array_merge($params, $this->getAcInformation($params)); $requiredOrderParams = $this->requiredOrderParamsMissing($type, $params); - + if (!empty($requiredOrderParams)) { throw new PostnlException( // @codingStandardsIgnoreLine // @todo POSTNL-XXX toevoegen // @codingStandardsIgnoreLine - __('Missing required parameters: %1', implode(', ',$requiredOrderParams)) + __('Missing required parameters: %1', implode(', ', $requiredOrderParams)) ); } - + return $params; } - + /** * @param string $type * @param array $params @@ -136,15 +145,16 @@ public function get($params) private function requiredOrderParamsMissing($type, $params) { $requiredList = $this->setRequiredList($type); - + $missing = array_filter($requiredList, function ($value, $key) use ($params) { $paramValue = isset($params[$key]) && !empty($params[$key]) ? $params[$key] : false; + return !$paramValue && true == $value; }, \Zend\Stdlib\ArrayUtils::ARRAY_FILTER_USE_BOTH); - + return array_keys($missing); } - + /** * @param $type * @@ -156,10 +166,10 @@ private function setRequiredList($type) foreach ($this->optionParams as $key => $value) { $list[$key] = $value[$type]; } - + return $list; } - + /** * If you want to store the param inside the tig_postnl_order table, * you need to give the keys the same name as the column names. @@ -167,11 +177,13 @@ private function setRequiredList($type) * @param $params * * @return array + * @throws PostnlException */ private function formatParamData($params) { - $productInfo = $this->productCodeAndType->get($params['type'], $params['option'], $params['country']); - + $option = isset($params['option']) ? $params['option'] : 'Daytime'; + $productInfo = $this->productCodeAndType->get($params['type'], $option, $params['country']); + return [ 'quote_id' => isset($params['quote_id']) ? $params['quote_id'] : '', 'delivery_date' => isset($params['date']) ? $params['date'] : '', @@ -181,17 +193,18 @@ private function formatParamData($params) 'pg_location_code' => isset($params['LocationCode']) ? $params['LocationCode'] : '', 'pg_retail_network_id' => isset($params['RetailNetworkID']) ? $params['RetailNetworkID'] : '', 'pg_address' => $this->addExtraToAddress($params), - 'type' => $params['option'], + 'type' => $option, 'opening_hours' => isset($params['OpeningHours']) ? $params['OpeningHours'] : '', 'fee' => $this->feeCalculator->get($params), 'product_code' => $productInfo['code'], ]; } - + /** - * Get the AgentCodes for specifiec type consignments + * Get the AgentCodes for specific type consignments * * formatParamData + * * @param $params * * @return array @@ -202,13 +215,13 @@ private function getAcInformation($params) if (!$acOptions) { return []; } - + return [ 'ac_characteristic' => $acOptions['Characteristic'], 'ac_option' => $acOptions['Option'] ]; } - + /** * @param $params * @@ -220,18 +233,22 @@ private function addExtraToAddress($params) if (!isset($params['address'])) { return false; } - + + if ($params['type'] == 'fallback') { + $params['customerData'] = $params['address']; + } + $params['address']['Name'] = isset($params['name']) ? $params['name'] : ''; - + if (!isset($params['customerData'])) { throw new PostnlException( // @codingStandardsIgnoreLine - __('Missing required parameters : customerData') + __('Missing required parameters: customerData') ); } - + $params['address']['customer'] = $params['customerData']; - + return $params['address']; } } diff --git a/view/frontend/web/js/Renderer/DeliveryOptions/Delivery.js b/view/frontend/web/js/Renderer/DeliveryOptions/Delivery.js index 8d82ccf68..23a430590 100644 --- a/view/frontend/web/js/Renderer/DeliveryOptions/Delivery.js +++ b/view/frontend/web/js/Renderer/DeliveryOptions/Delivery.js @@ -109,13 +109,11 @@ define([ State.currentSelectedShipmentType('delivery'); State.selectShippingMethod(); - if (value.fallback) { - return; - } - var fee = null; - if (value.hasFee()) { - fee = value.getFee(); + if (!value.fallback) { + if (value.hasFee()) { + fee = value.getFee(); + } } State.fee(fee); @@ -126,12 +124,13 @@ define([ method : 'POST', url : window.checkoutConfig.shipping.postnl.urls.deliveryoptions_save, data : { - type : 'delivery', + address: AddressFinder(), + type : (typeof value.fallback !== 'undefined') ? 'fallback' : 'delivery', date : value.date, option : value.option, from : value.from, to : value.to, - country: value.address.country + country: (typeof value.address !== 'undefined') ? value.address.country : AddressFinder().country } }).done(function (response) { $(document).trigger('compatible_postnl_deliveryoptions_save_done', {response: response}); From 75617d80284cc5bbcf8a48c5623c6eb4c8f53ad8 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 1 May 2019 15:23:22 +0200 Subject: [PATCH 063/113] POSTNLM2-795: Using a giant data-array, so impossible to comply to Calisthenics conventions. --- Helper/DeliveryOptions/OrderParams.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Helper/DeliveryOptions/OrderParams.php b/Helper/DeliveryOptions/OrderParams.php index 636b49386..5674db7e0 100644 --- a/Helper/DeliveryOptions/OrderParams.php +++ b/Helper/DeliveryOptions/OrderParams.php @@ -30,6 +30,7 @@ * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US */ +// @codingStandardsIgnoreFile namespace TIG\PostNL\Helper\DeliveryOptions; use TIG\PostNL\Exception as PostnlException; @@ -126,9 +127,7 @@ public function get($params) if (!empty($requiredOrderParams)) { throw new PostnlException( - // @codingStandardsIgnoreLine // @todo POSTNL-XXX toevoegen - // @codingStandardsIgnoreLine __('Missing required parameters: %1', implode(', ', $requiredOrderParams)) ); } @@ -242,7 +241,6 @@ private function addExtraToAddress($params) if (!isset($params['customerData'])) { throw new PostnlException( - // @codingStandardsIgnoreLine __('Missing required parameters: customerData') ); } From 0579dd5ccaea0fab3d257514ba29d54864d1e29d Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 2 May 2019 15:29:47 +0200 Subject: [PATCH 064/113] POSTNLM2-771: Trigger reload when tab (containing PDF) is closed to show generated warnings. --- .../templates/shipment/view/javascript.phtml | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/view/adminhtml/templates/shipment/view/javascript.phtml b/view/adminhtml/templates/shipment/view/javascript.phtml index ea872a8a2..70c3cc851 100644 --- a/view/adminhtml/templates/shipment/view/javascript.phtml +++ b/view/adminhtml/templates/shipment/view/javascript.phtml @@ -31,8 +31,24 @@ */ ?> From e9cdc24e13fea834e4d4f3ffbd7989f78c51274d Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 2 May 2019 16:08:41 +0200 Subject: [PATCH 065/113] POSTNLM2-771: Trigger reload when tab (containing PDF) loses focus to show generated warnings. --- view/adminhtml/templates/shipment/view/javascript.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/view/adminhtml/templates/shipment/view/javascript.phtml b/view/adminhtml/templates/shipment/view/javascript.phtml index 70c3cc851..fb3c024ae 100644 --- a/view/adminhtml/templates/shipment/view/javascript.phtml +++ b/view/adminhtml/templates/shipment/view/javascript.phtml @@ -33,7 +33,7 @@