From 0c47da0b49948557d8eac1b5f6b504c3ab16524d Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 14 Feb 2019 15:03:12 +0100 Subject: [PATCH 01/26] POSTNLM2-763: Corrected default value. Was 4950. Should be 4952. --- etc/config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/config.xml b/etc/config.xml index 05189aca7..42ecce7fc 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -88,7 +88,7 @@ 3085 4946 - 4950 + 4952 0 From c866b850ba084e2b582b37561899c1332f74585c Mon Sep 17 00:00:00 2001 From: Mickey Beijer Date: Wed, 20 Feb 2019 16:03:18 +0100 Subject: [PATCH 02/26] POSTNLM2-764 : bugfix where shipping options dropdown might not be shown when creating a shipment --- Config/Source/Options/ProductOptions.php | 2 +- Helper/AddressEnhancer.php | 2 +- Service/Options/ShipmentSupported.php | 29 ++++++++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Config/Source/Options/ProductOptions.php b/Config/Source/Options/ProductOptions.php index 80ecf79c6..22b06cc9a 100644 --- a/Config/Source/Options/ProductOptions.php +++ b/Config/Source/Options/ProductOptions.php @@ -160,7 +160,7 @@ public function getEpsProductOptions($address = false) if ($address && $address->getCountryId() === 'ES' && $this->canaryConverter->isCanaryIsland($address)) { return $this->getGlobalPackOptions(); } - return $this->getProductoptions(['group' => 'eu_options']); + return $this->getProductoptions(['isEvening' => false, 'countryLimitation' => false, 'group' => 'eu_options']); } /** diff --git a/Helper/AddressEnhancer.php b/Helper/AddressEnhancer.php index fc1197e36..40b7b1c2a 100644 --- a/Helper/AddressEnhancer.php +++ b/Helper/AddressEnhancer.php @@ -150,7 +150,7 @@ protected function parseResult($result, $address) } $address['housenumberExtension'] = ''; - if ($result['addition']) { + if (isset($result['addition']) && $result['addition']) { $address['housenumberExtension'] = trim($result['addition']); } diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index 9dcc63a7e..2373597ed 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -33,6 +33,7 @@ use TIG\PostNL\Config\Source\Options\ProductOptions; use TIG\PostNL\Config\Provider\ProductOptions as OptionsProvider; +use TIG\PostNL\Service\Shipment\EpsCountries; class ShipmentSupported { @@ -79,18 +80,36 @@ private function availableOptions($country) // These are the options selected in the configuration by user. $supportedOptions = $this->optionsProvider->getSupportedProductOptions(); - $optionsAllowed = $this->getProductOptions($country); - if (!in_array($country, $this->allowedCountries)) { - $optionsAllowed = $this->productOptions->getEpsProductOptions(); - } + $optionsAllowed = $this->getProductOptionsByCountry($country); $availableOptions = array_filter($supportedOptions, function ($value) use ($optionsAllowed) { - return isset($optionsAllowed[$value]); + $available = false; + foreach ($optionsAllowed as $option) { + $available = ($available || (isset($option['value']) && $option['value'] == $value)); + } + + return $available; }); return $availableOptions; } + private function getProductOptionsByCountry($country) + { + if (in_array($country, $this->allowedCountries)) { + $options = $this->getProductOptions($country); + return $options; + } + + if (in_array($country, EpsCountries::ALL)) { + $options = $this->productOptions->getEpsProductOptions(); + return $options; + } + + $options = $this->productOptions->getGlobalPackOptions(); + return $options; + } + /** * @param $country * From c91458a0196a343524c05d0bd456ee6978c4f66d Mon Sep 17 00:00:00 2001 From: Mickey Beijer Date: Thu, 21 Feb 2019 13:48:03 +0100 Subject: [PATCH 03/26] POSTNLM2-764 : Domestic shipments doesn't show all product codes anymore --- Service/Options/ShipmentSupported.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/Options/ShipmentSupported.php b/Service/Options/ShipmentSupported.php index 2373597ed..9e4b8bad6 100644 --- a/Service/Options/ShipmentSupported.php +++ b/Service/Options/ShipmentSupported.php @@ -119,7 +119,7 @@ private function getProductOptions($country) { $options = $this->productOptions->get(); return array_filter($options, function ($value) use ($country) { - return (!$value['countryLimitation'] || $value['countryLimitation'] == $country); + return ($value['countryLimitation'] == $country); }); } } From edcd9a59a45897c3feb998774faebd383e8dcde2 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 26 Feb 2019 16:24:44 +0100 Subject: [PATCH 04/26] POSTNLM2-757: ShipmentDays filter can be used again. Fixed typo in strtotime function. --- Helper/Data.php | 4 ++-- Webservices/Endpoints/Locations.php | 2 +- etc/frontend/di.xml | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 43297fa60..7ffaa2846 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -159,10 +159,10 @@ public function getDayOrWeekNumber($date, $format = 'w') /** * @return bool|string */ - public function getTommorowsDate() + public function getTomorrowsDate() { $dateTime = $this->dateTime->date($this->getCurrentDate()); - return date('Y-m-d ' . $dateTime->format('H:i:s'), strtotime('tommorow')); + return date('Y-m-d ' . $dateTime->format('H:i:s'), strtotime('tomorrow')); } /** diff --git a/Webservices/Endpoints/Locations.php b/Webservices/Endpoints/Locations.php index 7c48c4bdc..daa70d2ad 100644 --- a/Webservices/Endpoints/Locations.php +++ b/Webservices/Endpoints/Locations.php @@ -139,7 +139,7 @@ public function getDeliveryDate($startDate) return $startDate; } - return $this->postNLhelper->getTommorowsDate(); + return $this->postNLhelper->getTomorrowsDate(); } /** diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 2ad390a1b..8ff83c08c 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -67,8 +67,7 @@ \TIG\PostNL\Service\Timeframe\Filters\Days\Sunday \TIG\PostNL\Service\Timeframe\Filters\Days\SameDay - - + \TIG\PostNL\Service\Timeframe\Filters\Days\ShipmentDays \TIG\PostNL\Service\Timeframe\Filters\Days\CutOffTimes From f087860bd191e2c44919dc7bc4cfc3ed28d5dd77 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 5 Mar 2019 11:00:00 +0100 Subject: [PATCH 05/26] Test 2.2.7 on PHP 7.1 and 2.2.6 on PHP 7.0. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index eec94c08f..41e9aed98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,12 +42,14 @@ env: # - MAGENTO_VERSION=2.2.4 # - MAGENTO_VERSION=2.2.5 - MAGENTO_VERSION=2.2.6 - - MAGENTO_VERSION=2.2.7 + # - MAGENTO_VERSION=2.2.7 matrix: # PHP 7.1 would be supported in Magento since Magento 2.2 # And there wouldn't be support of PHP 7.1 in Magento 2.0 or 2.1 include: + - php: 7.1 + env: MAGENTO_VERSION=2.2.7 - php: 7.2 env: MAGENTO_VERSION=2.3.0 - php: 7.1 From e1bc0b72f4f346d93f2938219908510798bfc105 Mon Sep 17 00:00:00 2001 From: Dennis van der Hammen Date: Wed, 6 Mar 2019 13:04:04 +0100 Subject: [PATCH 06/26] Added a security warning in the template issue --- .github/ISSUE_TEMPLATE.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index f05d3ce3e..81f7022ba 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -22,6 +22,12 @@ Issues with outdated version will be rejected. --- +### If your issue contains security sensitive information +** If your issue may contain sensitive information, please send us an e-mail at security@tig.nl.** +- [ ] This issue does not contain any security sensitive information + +--- + ### If the purpose of your issue is a *feature request* - As a *..certain type of user..* I’d like to *..describe what you want..* in order to *..write goal(s)..* - Suggestions and background: @@ -40,4 +46,4 @@ Issues with outdated version will be rejected. ### TIG support - Please ask your question in English to ensure that your issue can help other people internationally. Nevertheless we will respond in English. -- If you want support with installing the PostNL extension, please contact citservicedesk@postnl.nl for free support, or contact us directly at support@tig.nl for paid support plans. \ No newline at end of file +- If you want support with installing the PostNL extension, please contact citservicedesk@postnl.nl for free support, or contact us directly at support@tig.nl for paid support plans. From e03c0b5dbf925aec5c111bd740b4b309f5d2ecbf Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 13 Mar 2019 16:25:07 +0100 Subject: [PATCH 07/26] POSTNLM2-755: Re-factored 'Change Confirmation'-flows to 'Cancel Confirmation'. --- Block/Adminhtml/Shipment/View.php | 13 +++++---- ...onfirmation.php => CancelConfirmation.php} | 29 ++++++++++--------- ...rmation.php => MassCancelConfirmation.php} | 8 +++-- ...ionTest.php => CancelConfirmationTest.php} | 8 +++-- ...ionTest.php => CancelConfirmationTest.php} | 8 +++-- i18n/en_US.csv | 2 +- i18n/nl_NL.csv | 2 +- .../sales_order_shipment_grid.xml | 8 ++--- 8 files changed, 46 insertions(+), 32 deletions(-) rename Controller/Adminhtml/Shipment/{ChangeConfirmation.php => CancelConfirmation.php} (84%) rename Controller/Adminhtml/Shipment/{MassChangeConfirmation.php => MassCancelConfirmation.php} (90%) rename Test/Integration/Controller/Adminhml/Shipment/{ChangeConfirmationTest.php => CancelConfirmationTest.php} (89%) rename Test/Integration/Service/Shipment/Confirming/{ChangeConfirmationTest.php => CancelConfirmationTest.php} (90%) diff --git a/Block/Adminhtml/Shipment/View.php b/Block/Adminhtml/Shipment/View.php index f49750d5f..1b4e132c0 100644 --- a/Block/Adminhtml/Shipment/View.php +++ b/Block/Adminhtml/Shipment/View.php @@ -145,15 +145,15 @@ private function setPostNLPrintLabelButton() } /** - * Add the PostNL change confirmation button. + * Add the PostNL cancel confirmation button. */ - private function setPostNLChangeConfirmButton() + private function setPostNLCancelConfirmButton() { /** @codingStandardsIgnoreStart */ $this->buttonList->add( - 'postnl_change_confirm', + 'postnl_cancel_confirm', [ - 'label' => __('PostNL - Change Confirmation'), + 'label' => __('PostNL - Cancel Confirmation'), 'class' => 'delete primary', 'onclick' => 'deleteConfirm(\'' . __( @@ -216,7 +216,7 @@ private function setPostNLPrintLabelButtonData() $confirmedAt = $postNLShipment->getConfirmedAt(); if (!empty($confirmedAt)) { $this->buttonList->remove('postnl_print'); - $this->setPostNLChangeConfirmButton(); + $this->setPostNLCancelConfirmButton(); } if (empty($confirmedAt) && $postNLShipment->getMainBarcode()) { @@ -274,13 +274,14 @@ private function getAlterUrl() $postNLShipment = $this->getPostNLShipment(); return $this->getUrl( - 'postnl/shipment/ChangeConfirmation', + 'postnl/shipment/CancelConfirmation', [ 'postnl_shipment_id' => $postNLShipment->getId(), 'shipment_id' => $this->getShipment()->getId(), ] ); } + /** * @return \TIG\PostNL\Api\Data\ShipmentInterface|null */ diff --git a/Controller/Adminhtml/Shipment/ChangeConfirmation.php b/Controller/Adminhtml/Shipment/CancelConfirmation.php similarity index 84% rename from Controller/Adminhtml/Shipment/ChangeConfirmation.php rename to Controller/Adminhtml/Shipment/CancelConfirmation.php index 0385ecb42..69fc2eef7 100644 --- a/Controller/Adminhtml/Shipment/ChangeConfirmation.php +++ b/Controller/Adminhtml/Shipment/CancelConfirmation.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\Controller\Adminhtml\Shipment; use Magento\Backend\App\Action; @@ -37,32 +38,31 @@ use TIG\PostNL\Service\Shipment\ShipmentService; use TIG\PostNL\Service\Shipment\ResetPostNLShipment; -class ChangeConfirmation extends Action +class CancelConfirmation extends Action { /** * @var ShipmentService */ private $shipmentService; - + /** * @var ResetPostNLShipment */ private $resetService; - + /** * @var int */ private $postNLShipmentId; - + /** * @var int */ private $shipmentId; - + /** * @param Context $context * @param ShipmentService $shipmentService - */ public function __construct( Context $context, @@ -70,26 +70,29 @@ public function __construct( ResetPostNLShipment $resetService ) { parent::__construct($context); - - $this->shipmentService = $shipmentService; - $this->resetService = $resetService; + + $this->shipmentService = $shipmentService; + $this->resetService = $resetService; } - + /** * When you change the consignment confirmation, * all the associated elements in question will be removed from the shipment. * After that, new information like the shipping address can be set, before re-confirming the consignment. * - * @return \Magento\Framework\Controller\Result\Redirect + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface + * @throws \Magento\Framework\Exception\CouldNotDeleteException + * @throws \Magento\Framework\Exception\CouldNotSaveException */ public function execute() { $this->postNLShipmentId = $this->getRequest()->getParam('postnl_shipment_id'); $this->shipmentId = $this->getRequest()->getParam('shipment_id'); - + $this->resetService->resetShipment($this->shipmentId); - + $resultDirect = $this->resultRedirectFactory->create(); + return $resultDirect->setPath( 'sales/shipment/view', ['shipment_id' => $this->shipmentId] diff --git a/Controller/Adminhtml/Shipment/MassChangeConfirmation.php b/Controller/Adminhtml/Shipment/MassCancelConfirmation.php similarity index 90% rename from Controller/Adminhtml/Shipment/MassChangeConfirmation.php rename to Controller/Adminhtml/Shipment/MassCancelConfirmation.php index 659d855b2..863735205 100644 --- a/Controller/Adminhtml/Shipment/MassChangeConfirmation.php +++ b/Controller/Adminhtml/Shipment/MassCancelConfirmation.php @@ -38,7 +38,7 @@ use Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory as ShipmentCollectionFactory; use TIG\PostNL\Service\Shipment\ResetPostNLShipment; -class MassChangeConfirmation extends Action +class MassCancelConfirmation extends Action { /** * @var Filter @@ -77,11 +77,13 @@ public function __construct( $this->collectionFactory = $collectionFactory; $this->resetService = $resetService; } - + /** * Dispatch request * - * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface + * @throws \Magento\Framework\Exception\CouldNotDeleteException + * @throws \Magento\Framework\Exception\CouldNotSaveException * @throws \Magento\Framework\Exception\LocalizedException */ public function execute() diff --git a/Test/Integration/Controller/Adminhml/Shipment/ChangeConfirmationTest.php b/Test/Integration/Controller/Adminhml/Shipment/CancelConfirmationTest.php similarity index 89% rename from Test/Integration/Controller/Adminhml/Shipment/ChangeConfirmationTest.php rename to Test/Integration/Controller/Adminhml/Shipment/CancelConfirmationTest.php index 9ad10b762..d1c9517b3 100644 --- a/Test/Integration/Controller/Adminhml/Shipment/ChangeConfirmationTest.php +++ b/Test/Integration/Controller/Adminhml/Shipment/CancelConfirmationTest.php @@ -37,8 +37,12 @@ use TIG\PostNL\Model\ShipmentFactory; use TIG\PostNL\Model\ShipmentRepository; -class ChangeConfirmationTest extends AbstractBackendController +class CancelConfirmationTest extends AbstractBackendController { + /** + * @throws \Magento\Framework\Exception\CouldNotSaveException + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ public function testResetsTheMainBarcode() { if (getenv('TRAVIS') !== false) { @@ -59,7 +63,7 @@ public function testResetsTheMainBarcode() $this->_objectManager->get('Magento\Backend\Model\UrlInterface')->turnOffSecretKey(); $this->dispatch( - 'backend/postnl/shipment/ChangeConfirmation/postnl_shipment_id/' . $model->getId() . '/shipment_id/' + 'backend/postnl/shipment/CancelConfirmation/postnl_shipment_id/' . $model->getId() . '/shipment_id/' . $shipment->getId() ); diff --git a/Test/Integration/Service/Shipment/Confirming/ChangeConfirmationTest.php b/Test/Integration/Service/Shipment/Confirming/CancelConfirmationTest.php similarity index 90% rename from Test/Integration/Service/Shipment/Confirming/ChangeConfirmationTest.php rename to Test/Integration/Service/Shipment/Confirming/CancelConfirmationTest.php index 01ccc1d20..653b3e820 100644 --- a/Test/Integration/Service/Shipment/Confirming/ChangeConfirmationTest.php +++ b/Test/Integration/Service/Shipment/Confirming/CancelConfirmationTest.php @@ -34,10 +34,14 @@ use TIG\PostNL\Service\Shipment\ResetPostNLShipment; use TIG\PostNL\Test\Integration\TestCase; -class ChangeConfirmationTest extends TestCase +class CancelConfirmationTest extends TestCase { public $instanceClass = ResetPostNLShipment::class; - + + /** + * @throws \Magento\Framework\Exception\CouldNotDeleteException + * @throws \Magento\Framework\Exception\CouldNotSaveException + */ public function testResetPostNLShipment() { $postNLShipment = require realpath(__DIR__ . '/../../../../Fixtures/Shipments/PostNLShipment.php'); diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 6ad751f93..ca71eba5a 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -173,7 +173,7 @@ Percent,Percent "From 15:00","From 15:00" "PostNL - Confirm And Print Shipment Label","PostNL - Confirm And Print Shipment Label" "Send Shipment Email","Send Shipment Email" -"PostNL - Change Confirmation","PostNL - Change Confirmation" +"PostNL - Cancel Confirmation","PostNL - Cancel Confirmation" "Are you sure that you wish to reset the confirmation status of this shipment? You will need to confirm this shipment with PostNL again before you can send it. This action will remove all barcodes and labels associated with this shipment. You can not undo this action.","Are you sure that you wish to reset the confirmation status of this shipment? You will need to confirm this shipment with PostNL again before you can send it. This action will remove all barcodes and labels associated with this shipment. You can not undo this action." "PostNL - Print label","PostNL - Print label" "Default postoffice early pickup option","Default postoffice early pickup option" diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index e902845e3..8ac335636 100644 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -190,7 +190,7 @@ Percent,Percentage "From 15:00","Vanaf 15:00" "PostNL - Confirm And Print Shipment Label","PostNL - Voormelden en label printen" "Send Shipment Email","Verstuur verzending e-mail" -"PostNL - Change Confirmation","PostNL - Voormelding wijzigen" +"PostNL - Cancel Confirmation","PostNL - Voormelding verwijderen" "Are you sure that you wish to reset the confirmation status of this shipment? You will need to confirm this shipment with PostNL again before you can send it. This action will remove all barcodes and labels associated with this shipment. You can not undo this action.","Weet je zeker dat je de voormelding van deze verzending wilt wijzgen? De verzending zal opnieuw voorgemeld moeten worden voordat je deze alsnog kunt verzenden. Deze actie verwijdert alle barcodes en labels die bij deze verzending horen. Dit kan niet ongedaan worden gemaakt." "PostNL - Print label","PostNL - Print label" "Default postoffice early pickup option","Standaard ophalen bij PostNL locatie extra vroeg optie" diff --git a/view/adminhtml/ui_component/sales_order_shipment_grid.xml b/view/adminhtml/ui_component/sales_order_shipment_grid.xml index 331788b53..4fc944176 100644 --- a/view/adminhtml/ui_component/sales_order_shipment_grid.xml +++ b/view/adminhtml/ui_component/sales_order_shipment_grid.xml @@ -62,12 +62,12 @@ - + - postnl_mass_change_confirmation - PostNL - Change Confirmation - + postnl_mass_cancel_confirmation + PostNL - Cancel Confirmation + From 303c2584117a02cfab22bbf7aa63d98fc7fd02cf Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 19 Mar 2019 14:00:50 +0100 Subject: [PATCH 08/26] POSTNLM2-777: Fixed bug where weight wasn't calculated properly when multiple --- Service/Parcel/Order/Count.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/Parcel/Order/Count.php b/Service/Parcel/Order/Count.php index bdc3b980b..96e159849 100644 --- a/Service/Parcel/Order/Count.php +++ b/Service/Parcel/Order/Count.php @@ -44,6 +44,6 @@ class Count extends CountAbstract public function get(OrderInterface $order) { $items = $order->getItems(); - return $this->calculate($this->getWeight($items), $items); + return $this->calculate($order->getWeight(), $items); } } From 1dc36d6a65e71da21c1ec53cc27562de073107a7 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 19 Mar 2019 14:29:22 +0100 Subject: [PATCH 09/26] POSTNLM2-777: Re-factored code to comply with MEQP2 conventions. --- Service/Parcel/CollectAbstract.php | 10 ++- Service/Parcel/CountAbstract.php | 112 +++++++++++------------------ Service/Parcel/Quote/Count.php | 49 ------------- 3 files changed, 45 insertions(+), 126 deletions(-) delete mode 100644 Service/Parcel/Quote/Count.php diff --git a/Service/Parcel/CollectAbstract.php b/Service/Parcel/CollectAbstract.php index ca7a38306..343e134ae 100644 --- a/Service/Parcel/CollectAbstract.php +++ b/Service/Parcel/CollectAbstract.php @@ -42,15 +42,13 @@ abstract class CollectAbstract const ATTRIBUTE_PARCEL_COUNT = 'postnl_parcel_count'; /** @var \TIG\PostNL\Service\Options\ProductDictionary $productDictionary */ - // @codingStandardsIgnoreLine - protected $productDictionary; + private $productDictionary; /** @var \TIG\PostNL\Service\Product\CollectionByAttributeValue $collectionByAttributeValue */ - // @codingStandardsIgnoreLine - protected $collectionByAttributeValue; + private $collectionByAttributeValue; - // @codingStandardsIgnoreLine - protected $shippingOptions; + /** @var \TIG\PostNL\Config\Provider\ShippingOptions $shippingOptions */ + private $shippingOptions; /** * CollectAbstract constructor. diff --git a/Service/Parcel/CountAbstract.php b/Service/Parcel/CountAbstract.php index 54b3de681..3c40e7a09 100644 --- a/Service/Parcel/CountAbstract.php +++ b/Service/Parcel/CountAbstract.php @@ -42,29 +42,24 @@ abstract class CountAbstract extends CollectAbstract { const CALCULATE_LABELS_WEIGHT = 'weight'; + const CALCULATE_LABELS_PARCEL_COUNT = 'parcel_count'; - - // @codingStandardsIgnoreLine - protected $collectionByAttributeValue; - - // @codingStandardsIgnoreLine - protected $shippingOptions; - - // @codingStandardsIgnoreLine - protected $labelOptions; - - // @codingStandardsIgnoreLine - protected $products; - - // @codingStandardsIgnoreLine - protected $quantities; - + + /** @var \TIG\PostNL\Config\Provider\LabelAndPackingslipOptions */ + private $labelOptions; + + /** @var $products */ + private $products; + + /** @var $quantities */ + private $quantities; + /** * CountAbstract constructor. * - * @param \TIG\PostNL\Service\Options\ProductDictionary $productDictionary + * @param \TIG\PostNL\Service\Options\ProductDictionary $productDictionary * @param \TIG\PostNL\Service\Product\CollectionByAttributeValue $collectionByAttributeValue - * @param \TIG\PostNL\Config\Provider\ShippingOptions $shippingOptions + * @param \TIG\PostNL\Config\Provider\ShippingOptions $shippingOptions * @param \TIG\PostNL\Config\Provider\LabelAndPackingslipOptions $labelOptions */ public function __construct( @@ -73,44 +68,40 @@ public function __construct( ShippingOptions $shippingOptions, LabelOptions $labelOptions ) { - $this->productDictionary = $productDictionary; - $this->collectionByAttributeValue = $collectionByAttributeValue; - $this->shippingOptions = $shippingOptions; - $this->labelOptions = $labelOptions; + $this->labelOptions = $labelOptions; parent::__construct( $productDictionary, $collectionByAttributeValue, $shippingOptions ); } - + /** * @param $weight * @param $items * * @return int */ - // @codingStandardsIgnoreLine - protected function calculate($weight, $items) + public function calculate($weight, $items) { $this->products = $this->getProductsByType($items); if (empty($this->products)) { return $this->getBasedOnWeight($weight); } - + foreach ($items as $orderItem) { /** @var $orderItem OrderItemInterface */ $this->quantities[$orderItem->getProductId()] = $orderItem->getQtyOrdered(); } - + $labelOption = $this->labelOptions->getCalculateLabels(); if ($labelOption == self::CALCULATE_LABELS_PARCEL_COUNT) { return $this->calculateByParcelCount($weight, $items); } - + return $this->calculateByWeight($weight, $items); } - + /** * When 'parcel_count' is selected to calculate parcel count. Products without a * specified 'parcel_count' will still be calculated by weight. @@ -120,30 +111,29 @@ protected function calculate($weight, $items) * * @return int */ - // @codingStandardsIgnoreLine - protected function calculateByParcelCount($weight, $items) + private function calculateByParcelCount($weight, $items) { - $parcelCount = 0; + $parcelCount = 0; $productsWithParcelCount = $this->getProductsWithParcelCount($items); if (!$productsWithParcelCount) { return $this->getBasedOnWeight($weight); } - + $subtractWeight = 0; foreach ($productsWithParcelCount as $item) { $parcelCount += $this->getBasedOnParcelCount($item); $subtractWeight += $item->getWeight(); } - + $productsWithoutParcelCount = $this->getProductsWithoutParcelCount($items); if (!$productsWithoutParcelCount) { return $parcelCount; } $parcelCount += $this->getBasedOnWeight($weight - $subtractWeight); - + return $parcelCount; } - + /** * When 'weight' is selected to calculate parcel count. The total parcel count for * Extra@Home products is calculated separately. @@ -153,29 +143,28 @@ protected function calculateByParcelCount($weight, $items) * * @return int */ - // @codingStandardsIgnoreLine - protected function calculateByWeight($weight, $items) + private function calculateByWeight($weight, $items) { $extraAtHomeProducts = $this->getExtraAtHomeProducts($items); if (!$extraAtHomeProducts) { return $this->getBasedOnWeight($weight); } - - $parcelCount = 0; + + $parcelCount = 0; $subtractWeight = 0; foreach ($extraAtHomeProducts as $item) { $parcelCount += $this->getBasedOnParcelCount($item); $subtractWeight += $item->getWeight(); } - + $weight = $weight - $subtractWeight; if ($weight > 0) { $parcelCount += $this->getBasedOnWeight($weight); } - + return $parcelCount; } - + /** * When 'weight' is selected to calculate parcel count. * @@ -183,17 +172,17 @@ protected function calculateByWeight($weight, $items) * * @return float|int */ - // @codingStandardsIgnoreLine - protected function getBasedOnWeight($weight) + private function getBasedOnWeight($weight) { $labelOption = $this->labelOptions->getCalculateLabels(); // @codingStandardsIgnoreLine - $maxWeight = ($labelOption == self::CALCULATE_LABELS_WEIGHT) ? $this->labelOptions->getCalculateLabelsMaxWeight() : 20000; + $maxWeight = ($labelOption == self::CALCULATE_LABELS_WEIGHT) ? $this->labelOptions->getCalculateLabelsMaxWeight() : 20000; $remainingParcelCount = ceil($weight / $maxWeight); - $weightCount = $remainingParcelCount < 1 ? 1 : $remainingParcelCount; + $weightCount = $remainingParcelCount < 1 ? 1 : $remainingParcelCount; + return $weightCount; } - + /** * Get parcel count of current item. * @@ -201,38 +190,19 @@ protected function getBasedOnWeight($weight) * * @return float|int */ - // @codingStandardsIgnoreLine - protected function getBasedOnParcelCount($item) + private function getBasedOnParcelCount($item) { if (!isset($this->products[$item->getId()])) { return 0; } - + /** @var ProductInterface $product */ - $product = $this->products[$item->getId()]; + $product = $this->products[$item->getId()]; $productParcelCount = $product->getCustomAttribute(self::ATTRIBUTE_PARCEL_COUNT); if ($productParcelCount) { return ($productParcelCount->getValue() * $this->quantities[$item->getId()]); } - + return 0; } - - /** - * Return weight of current item. - * - * @param $items - * - * @return int - */ - // @codingStandardsIgnoreLine - protected function getWeight($items) - { - $weight = 0; - foreach ($items as $item) { - /** @var ProductInterface $item */ - $weight += $item->getWeight(); - } - return $weight; - } } diff --git a/Service/Parcel/Quote/Count.php b/Service/Parcel/Quote/Count.php deleted file mode 100644 index 5eeae1816..000000000 --- a/Service/Parcel/Quote/Count.php +++ /dev/null @@ -1,49 +0,0 @@ -getAllItems(); - return $this->calculate($this->getWeight($items), $items); - } -} From 38b675b583f1de7ffc12709c9774f731dccc7c47 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 19 Mar 2019 14:31:45 +0100 Subject: [PATCH 10/26] POSTNLM2-777: Re-factored cause I don't see a reason why these getters shouldn't be public. --- Service/Parcel/CollectAbstract.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Service/Parcel/CollectAbstract.php b/Service/Parcel/CollectAbstract.php index 343e134ae..899026f7c 100644 --- a/Service/Parcel/CollectAbstract.php +++ b/Service/Parcel/CollectAbstract.php @@ -71,8 +71,7 @@ public function __construct( * * @return \Magento\Catalog\Api\Data\ProductInterface[] */ - // @codingStandardsIgnoreLine - protected function getProductsByType($items) + public function getProductsByType($items) { return $this->productDictionary->get( $items, @@ -85,8 +84,7 @@ protected function getProductsByType($items) * * @return array|\Magento\Catalog\Api\Data\ProductInterface[] */ - // @codingStandardsIgnoreLine - protected function getProductsWithoutParcelCount($items) + public function getProductsWithoutParcelCount($items) { return $this->collectionByAttributeValue->getByValue( $items, @@ -100,8 +98,7 @@ protected function getProductsWithoutParcelCount($items) * * @return array|\Magento\Catalog\Api\Data\ProductInterface[] */ - // @codingStandardsIgnoreLine - protected function getProductsWithParcelCount($items) + public function getProductsWithParcelCount($items) { return $this->collectionByAttributeValue->getByMinValue( $items, @@ -115,8 +112,7 @@ protected function getProductsWithParcelCount($items) * * @return array|\Magento\Catalog\Api\Data\ProductInterface[]|null */ - // @codingStandardsIgnoreLine - protected function getExtraAtHomeProducts($items) + public function getExtraAtHomeProducts($items) { if (!$this->shippingOptions->isExtraAtHomeActive()) { return null; From 757ae829d650f97f161afdc3ec921cf005995678 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Tue, 19 Mar 2019 14:32:48 +0100 Subject: [PATCH 11/26] POSTNLM2-777: Added phpdoc --- Service/Parcel/CollectAbstract.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Service/Parcel/CollectAbstract.php b/Service/Parcel/CollectAbstract.php index 899026f7c..51f2dd73e 100644 --- a/Service/Parcel/CollectAbstract.php +++ b/Service/Parcel/CollectAbstract.php @@ -49,12 +49,13 @@ abstract class CollectAbstract /** @var \TIG\PostNL\Config\Provider\ShippingOptions $shippingOptions */ private $shippingOptions; - + /** * CollectAbstract constructor. * - * @param \TIG\PostNL\Service\Options\ProductDictionary $productDictionary + * @param \TIG\PostNL\Service\Options\ProductDictionary $productDictionary * @param \TIG\PostNL\Service\Product\CollectionByAttributeValue $collectionByAttributeValue + * @param \TIG\PostNL\Config\Provider\ShippingOptions $shippingOptions */ public function __construct( ProductDictionary $productDictionary, From a5be93dc9ced20e68c12aae966b2ff5431ca35c6 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 20 Mar 2019 16:06:49 +0100 Subject: [PATCH 12/26] Small re-factor in Shipment\View --- Block/Adminhtml/Shipment/View.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Block/Adminhtml/Shipment/View.php b/Block/Adminhtml/Shipment/View.php index 1b4e132c0..653de658d 100644 --- a/Block/Adminhtml/Shipment/View.php +++ b/Block/Adminhtml/Shipment/View.php @@ -161,7 +161,7 @@ private function setPostNLCancelConfirmButton() . ' You will need to confirm this shipment with PostNL again before you can send it.' .' This action will remove all barcodes' . ' and labels associated with this shipment. You can not undo this action.' - ) . '\', \'' . $this->getAlterUrl() . '\')' + ) . '\', \'' . $this->getCancelConfirmationUrl() . '\')' ] ); /** @codingStandardsIgnoreEnd */ @@ -268,7 +268,7 @@ private function getConfirmUrl() /** * @return string */ - private function getAlterUrl() + private function getCancelConfirmationUrl() { /** @var PostNLShipment $postNLShipment */ $postNLShipment = $this->getPostNLShipment(); From e42420f467a6d40e473216033c96fe5e3516d798 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 10:17:07 +0100 Subject: [PATCH 13/26] POSTNLM2-769: Added logic to save Downpartner data during Labelling call and send it along with Confirming call. --- Api/Data/ShipmentInterface.php | 30 ++ Model/Shipment.php | 375 +++++++++++------- Service/Shipment/Data.php | 5 +- .../Shipment/Labelling/GenerateAbstract.php | 147 +++---- 4 files changed, 335 insertions(+), 222 deletions(-) diff --git a/Api/Data/ShipmentInterface.php b/Api/Data/ShipmentInterface.php index 9148fb387..c4389a6ba 100644 --- a/Api/Data/ShipmentInterface.php +++ b/Api/Data/ShipmentInterface.php @@ -221,6 +221,36 @@ public function getConfirmedAt(); * @return bool */ public function getConfirmed(); + + /** + * @return string|null + */ + public function setDownpartnerId($value); + + /** + * @return string|null + */ + public function getDownpartnerId(); + + /** + * @return string|null + */ + public function setDownpartnerLocation($value); + + /** + * @return string|null + */ + public function getDownpartnerLocation(); + + /** + * @return string|null + */ + public function setDownpartnerBarcode($value); + + /** + * @return string|null + */ + public function getDownpartnerBarcode(); /** * @param string $value diff --git a/Model/Shipment.php b/Model/Shipment.php index 892436c42..ac07a0059 100644 --- a/Model/Shipment.php +++ b/Model/Shipment.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\Model; use Magento\Framework\Stdlib\DateTime\DateTime; @@ -48,75 +49,96 @@ use Magento\Catalog\Api\ProductRepositoryInterface; // @codingStandardsIgnoreFile + /** * Too much public methods, and too much code. We can't get this file to pass the (Object Calistenics) code inspection. */ class Shipment extends AbstractModel implements ShipmentInterface, IdentityInterface { - const CACHE_TAG = 'tig_postnl_shipment'; - - const FIELD_SHIPMENT_ID = 'shipment_id'; - const FIELD_ORDER_ID = 'order_id'; - const FIELD_MAIN_BARCODE = 'main_barcode'; - const FIELD_PRODUCT_CODE = 'product_code'; - const FIELD_SHIPMENT_TYPE = 'shipment_type'; - const FIELD_AC_CHARACTERISTIC = 'ac_characteristic'; - const FIELD_AC_OPTION = 'ac_option'; - const FIELD_DELIVERY_DATE = 'delivery_date'; - const FIELD_IS_PAKJEGEMAK = 'is_pakjegemak'; - const FIELD_PG_LOCATION_CODE = 'pg_location_code'; + const CACHE_TAG = 'tig_postnl_shipment'; + + const FIELD_SHIPMENT_ID = 'shipment_id'; + + const FIELD_ORDER_ID = 'order_id'; + + const FIELD_MAIN_BARCODE = 'main_barcode'; + + const FIELD_PRODUCT_CODE = 'product_code'; + + const FIELD_SHIPMENT_TYPE = 'shipment_type'; + + const FIELD_AC_CHARACTERISTIC = 'ac_characteristic'; + + const FIELD_AC_OPTION = 'ac_option'; + + const FIELD_DELIVERY_DATE = 'delivery_date'; + + const FIELD_IS_PAKJEGEMAK = 'is_pakjegemak'; + + const FIELD_PG_LOCATION_CODE = 'pg_location_code'; + const FIELD_PG_RETAIL_NETWORK_ID = 'pg_retail_network_id'; - const FIELD_PARCEL_COUNT = 'parcel_count'; - const FIELD_SHIP_AT = 'ship_at'; - const FIELD_CONFIRMED_AT = 'confirmed_at'; - const FIELD_CONFIRMED = 'confirmed'; - + + const FIELD_PARCEL_COUNT = 'parcel_count'; + + const FIELD_SHIP_AT = 'ship_at'; + + const FIELD_CONFIRMED_AT = 'confirmed_at'; + + const FIELD_CONFIRMED = 'confirmed'; + + const FIELD_DOWNPARTNER_ID = 'downpartner_id'; + + const FIELD_DOWNPARTNER_LOCATION = 'downpartner_location'; + + const FIELD_DOWNPARTNER_BARCODE = 'downpartner_barcode'; + /** * @var string */ // @codingStandardsIgnoreLine protected $_eventPrefix = 'tig_postnl_shipment'; - + /** * @var OrderShipmentRepository $orderShipmentRepository */ private $orderShipmentRepository; - + /** * @var TimezoneInterface */ private $timezoneInterface; - + /** * @var OrderFactory */ private $orderFactory; - + /** * @var AddressFactory */ private $addressFactory; - + /** * @var ProductOptions */ private $productOptions; - + /** * @var ShipmentBarcodeRepositoryInterface */ private $barcodeRepository; - + /** * @var \Magento\Sales\Model\Order\Address */ private $shippingAddress; - + /** * @var ProductRepositoryInterface */ private $productRepository; - + /** * @param Context $context * @param Registry $registry @@ -148,16 +170,16 @@ public function __construct( array $data = [] ) { parent::__construct($context, $registry, $dateTime, $resource, $resourceCollection, $data); - + $this->orderShipmentRepository = $orderShipmentRepository; - $this->timezoneInterface = $timezoneInterface; - $this->orderFactory = $orderFactory; - $this->addressFactory = $addressFactory; - $this->productOptions = $productOptions; - $this->barcodeRepository = $barcodeRepository; - $this->productRepository = $productRepository; + $this->timezoneInterface = $timezoneInterface; + $this->orderFactory = $orderFactory; + $this->addressFactory = $addressFactory; + $this->productOptions = $productOptions; + $this->barcodeRepository = $barcodeRepository; + $this->productRepository = $productRepository; } - + /** * Constructor */ @@ -167,7 +189,7 @@ protected function _construct() // @codingStandardsIgnoreLine $this->_init('TIG\PostNL\Model\ResourceModel\Shipment'); } - + /** * @return array */ @@ -175,7 +197,7 @@ public function getIdentities() { return [self::CACHE_TAG . '_' . $this->getId()]; } - + /** * @return \Magento\Sales\Model\Order\Shipment */ @@ -183,7 +205,7 @@ public function getShipment() { return $this->orderShipmentRepository->get($this->getShipmentId()); } - + /** * @return Address */ @@ -192,26 +214,29 @@ public function getShippingAddress() if ($this->shippingAddress !== null) { return $this->shippingAddress; } - - $postNLOrder = $this->getPostNLOrder(); - $shipment = $this->getShipment(); + + $postNLOrder = $this->getPostNLOrder(); + $shipment = $this->getShipment(); $shippingAddress = $shipment->getShippingAddress(); - + if (!$postNLOrder->getIsPakjegemak()) { return $this->shippingAddress = $shippingAddress; } - + $pgOrderAddressId = $postNLOrder->getPgOrderAddressId(); - $order = $shipment->getOrder(); - $orderBillingId = $order->getBillingAddressId(); - + $order = $shipment->getOrder(); + $orderBillingId = $order->getBillingAddressId(); + $pgAddressStreet = implode("\n", $this->getPakjegemakAddress()->getStreet()); - - $shippingAddress = $this->filterShippingAddress([$pgOrderAddressId, $orderBillingId], $pgAddressStreet); - + + $shippingAddress = $this->filterShippingAddress([ + $pgOrderAddressId, + $orderBillingId + ], $pgAddressStreet); + return $this->shippingAddress = $shippingAddress; } - + /** * Mainly used when pakjegemak is available * @@ -220,10 +245,10 @@ public function getShippingAddress() public function getOriginalShippingAddress() { $shippingAddress = $this->getShippingAddress(); - + return $shippingAddress; } - + /** * @param array $ignoreAddressIds * @param $ignoreStreet @@ -235,31 +260,31 @@ private function filterShippingAddress($ignoreAddressIds, $ignoreStreet) $addressModel = $this->addressFactory->create(); /** @var \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $addressCollection */ $addressCollection = $addressModel->getCollection(); - + $addressCollection->addFieldToFilter('entity_id', ['nin' => $ignoreAddressIds]); $addressCollection->addFieldToFilter('parent_id', ['eq' => $this->getOrderId()]); $addressCollection->addFieldToFilter('street', ['neq' => $ignoreStreet]); - + // @codingStandardsIgnoreLine $shippingAddress = $addressCollection->setPageSize(1)->getFirstItem(); - + return $shippingAddress; } - + /** * @return Address */ public function getPakjegemakAddress() { - $postNLOrder = $this->getPostNLOrder(); + $postNLOrder = $this->getPostNLOrder(); $pgOrderAddressId = $postNLOrder->getPgOrderAddressId(); - + $PgOrderAddress = $this->addressFactory->create(); $PgOrderAddress->load($pgOrderAddressId); - + return $PgOrderAddress; } - + /** * @return Order */ @@ -267,30 +292,30 @@ public function getPostNLOrder() { $postNLOrder = $this->orderFactory->create(); $postNLOrder->load($this->getOrderId(), 'order_id'); - + return $postNLOrder; } - + /** * @return float|int */ public function getTotalWeight() { - $items = $this->getShipment()->getItems(); + $items = $this->getShipment()->getItems(); $weight = 0; - + /** @var Item $item */ foreach ($items as $item) { $weight += ($item->getWeight() * $item->getQty()); } - + if ($weight < 1) { $weight = 1; } - + return $weight; } - + /** * @param string $format * @@ -302,23 +327,24 @@ public function getDeliveryDateFormatted($format = 'd-m-Y H:i:s') if (!$deliveryDate) { $deliveryDate = $this->getDeliveryDateByOrder(); } - - $deliveryDate = $this->timezoneInterface->date($deliveryDate); + + $deliveryDate = $this->timezoneInterface->date($deliveryDate); $deliveryDateFormatted = $deliveryDate->format($format); - + return $deliveryDateFormatted; } - + /** * @param int *d + * * @return $this */ public function setShipmentId($value) { return $this->setData(static::FIELD_SHIPMENT_ID, $value); } - + /** * @return null|int */ @@ -326,7 +352,7 @@ public function getShipmentId() { return $this->getData(static::FIELD_SHIPMENT_ID); } - + /** * @param int * @@ -336,7 +362,7 @@ public function setOrderId($value) { return $this->setData(static::FIELD_ORDER_ID, $value); } - + /** * @return null|int */ @@ -344,7 +370,7 @@ public function getOrderId() { return $this->getData(static::FIELD_ORDER_ID); } - + /** * @param string * @@ -354,7 +380,7 @@ public function setMainBarcode($value) { return $this->setData(static::FIELD_MAIN_BARCODE, $value); } - + /** * @param int $currentShipmentNumber * @@ -365,16 +391,16 @@ public function getBarcode($currentShipmentNumber = 1) if ($currentShipmentNumber == 1) { return $this->getMainBarcode(); } - + $barcode = $this->barcodeRepository->getForShipment($this, $currentShipmentNumber); - + if (!$barcode) { return null; } - + return $barcode->getValue(); } - + /** * @return null|string */ @@ -382,7 +408,7 @@ public function getMainBarcode() { return $this->getData(static::FIELD_MAIN_BARCODE); } - + /** * @param string * @@ -392,7 +418,7 @@ public function setProductCode($value) { return $this->setData(static::FIELD_PRODUCT_CODE, $value); } - + /** * @return null|string */ @@ -400,7 +426,7 @@ public function getProductCode() { return $this->getData(static::FIELD_PRODUCT_CODE); } - + /** * @param string * @@ -410,7 +436,7 @@ public function setShipmentType($value) { return $this->setData(static::FIELD_SHIPMENT_TYPE, $value); } - + /** * @return null|string */ @@ -418,7 +444,7 @@ public function getShipmentType() { return $this->getData(static::FIELD_SHIPMENT_TYPE); } - + /** * @param $value * @@ -428,7 +454,7 @@ public function setAcCharacteristic($value) { return $this->setData(static::FIELD_AC_CHARACTERISTIC, $value); } - + /** * @return string|null */ @@ -436,7 +462,7 @@ public function getAcCharacteristic() { return $this->getData(static::FIELD_AC_CHARACTERISTIC); } - + /** * @param $value * @@ -446,7 +472,7 @@ public function setAcOption($value) { return $this->setData(static::FIELD_AC_OPTION, $value); } - + /** * @return string|null */ @@ -454,7 +480,7 @@ public function getAcOption() { return $this->getData(static::FIELD_AC_OPTION); } - + /** * @param string * @@ -464,7 +490,7 @@ public function setDeliveryDate($value) { return $this->setData(static::FIELD_DELIVERY_DATE, $value); } - + /** * @return null|string */ @@ -472,7 +498,7 @@ public function getDeliveryDate() { return $this->getData(static::FIELD_DELIVERY_DATE); } - + /** * @param string * @@ -482,7 +508,7 @@ public function setIsPakjegemak($value) { return $this->setData(static::FIELD_IS_PAKJEGEMAK, $value); } - + /** * @return null|string */ @@ -490,7 +516,7 @@ public function getIsPakjegemak() { return $this->getData(static::FIELD_IS_PAKJEGEMAK); } - + /** * @param string * @@ -500,7 +526,7 @@ public function setPgLocationCode($value) { return $this->setData(static::FIELD_PG_LOCATION_CODE, $value); } - + /** * @return null|string */ @@ -508,7 +534,7 @@ public function getPgLocationCode() { return $this->getData(static::FIELD_PG_LOCATION_CODE); } - + /** * @param string * @@ -518,7 +544,7 @@ public function setPgRetailNetworkId($value) { return $this->setData(static::FIELD_PG_RETAIL_NETWORK_ID, $value); } - + /** * @return null|string */ @@ -526,7 +552,7 @@ public function getPgRetailNetworkId() { return $this->getData(static::FIELD_PG_RETAIL_NETWORK_ID); } - + /** * @param $value * @@ -536,7 +562,7 @@ public function setParcelCount($value) { return $this->setData(static::FIELD_PARCEL_COUNT, $value); } - + /** * @return null|string */ @@ -544,7 +570,7 @@ public function getParcelCount() { return $this->getData(static::FIELD_PARCEL_COUNT); } - + /** * @param string * @@ -554,7 +580,7 @@ public function setShipAt($value) { return $this->setData(static::FIELD_SHIP_AT, $value); } - + /** * @return null|string */ @@ -562,7 +588,7 @@ public function getShipAt() { return $this->getData(static::FIELD_SHIP_AT); } - + /** * @param string * @@ -573,10 +599,10 @@ public function setConfirmedAt($value) if ($value !== null) { $this->_eventManager->dispatch('tig_postnl_set_confirmed_at_before', ['shipment' => $this]); } - + return $this->setData(static::FIELD_CONFIRMED_AT, $value); } - + /** * @return null|string */ @@ -584,7 +610,73 @@ public function getConfirmedAt() { return $this->getData(static::FIELD_CONFIRMED_AT); } - + + /** + * @param $value + * + * @return $this + */ + public function setConfirmed($value) + { + return $this->setData(static::FIELD_CONFIRMED, $value); + } + + /** + * @return mixed + */ + public function getConfirmed() + { + return $this->getData(static::FIELD_CONFIRMED); + } + + /** + * @return \TIG\PostNL\Model\Shipment + */ + public function setDownpartnerId($value) + { + return $this->setData(static::FIELD_DOWNPARTNER_ID, $value); + } + + /** + * @return mixed|string|null + */ + public function getDownpartnerId() + { + return $this->getData(static::FIELD_DOWNPARTNER_ID); + } + + /** + * @return \TIG\PostNL\Model\Shipment + */ + public function setDownpartnerLocation($value) + { + return $this->setData(static::FIELD_DOWNPARTNER_LOCATION, $value); + } + + /** + * @return mixed|string|null + */ + public function getDownpartnerLocation() + { + return $this->getData(static::FIELD_DOWNPARTNER_LOCATION); + } + + /** + * @return \TIG\PostNL\Model\Shipment + */ + public function setDownpartnerBarcode($value) + { + return $this->setData(static::FIELD_DOWNPARTNER_BARCODE, $value); + } + + /** + * @return mixed|string|null + */ + public function getDownpartnerBarcode() + { + return $this->getData(static::FIELD_DOWNPARTNER_BARCODE); + } + /** * Check if this shipment must be sent using Extra Cover. * @@ -593,18 +685,18 @@ public function getConfirmedAt() public function isExtraCover() { $productCodeOptions = $this->getProductCodeOptions(); - + if ($productCodeOptions === null) { return false; } - + if (!array_key_exists('isExtraCover', $productCodeOptions)) { return false; } - + return $productCodeOptions['isExtraCover']; } - + /** * @return bool */ @@ -612,35 +704,35 @@ public function isGlobalPack() { return $this->getShipmentType() == 'GP'; } - + /** * @return bool */ public function isExtraAtHome() { $productCodeOptions = $this->getProductCodeOptions(); - + if ($productCodeOptions === null) { return false; } - + return $productCodeOptions['group'] == 'extra_at_home_options'; } - + /** * @return bool */ public function isIDCheck() { $productCodeOptions = $this->getProductCodeOptions(); - + if ($productCodeOptions === null) { return false; } - + return $productCodeOptions['group'] == 'id_check_options'; } - + /** * @return float */ @@ -649,14 +741,14 @@ public function getExtraCoverAmount() $shipment = $this->getShipment(); $order = $shipment->getOrder(); $orderItems = $order->getItems(); - + $productPrices = $this->getPricePerProductId($orderItems); - + $shipmentItems = $shipment->getAllItems(); - + return $this->getTotalPrice($shipmentItems, $productPrices); } - + /** * @param \Magento\Sales\Api\Data\OrderItemInterface[]|\Magento\Sales\Model\Order\Item[] $orderItems * @@ -671,10 +763,10 @@ function ($orderItem) use (&$productPrices) { /** @var \Magento\Sales\Model\Order\Item $orderItem */ if ($orderItem->getProductType() == 'bundle') { $productPrices[$orderItem->getSku()] = $this->getBundledPrice($orderItem); - + return; } - + if ($orderItem->getProductType() != 'simple') { return; } @@ -683,10 +775,10 @@ function ($orderItem) use (&$productPrices) { $productPrices[$orderItem->getSku()] = $productPrice; } ); - + return $productPrices; } - + /** * @param $shipmentItems * @param $productPrices @@ -707,10 +799,10 @@ function ($shipmentItem) use ($productPrices, &$totalPrice) { $totalPrice += $productPrice * $shipmentItem->getQty(); } ); - + return $totalPrice; } - + /** * @param \Magento\Sales\Model\Order\Item $bundleItem * @@ -723,22 +815,23 @@ private function getBundledPrice($bundleItem) /** @var \Magento\Sales\Model\Order\Item $childItem */ foreach ($bundleItem->getChildrenItems() as $childItem) { $product = $this->productRepository->get($childItem->getSku()); - $qty = $childItem->getQtyOrdered() - ($childItem->getQtyShipped() - $childItem->getQtyCanceled()); + $qty = $childItem->getQtyOrdered() - ($childItem->getQtyShipped() - $childItem->getQtyCanceled()); $bundlePrice += $product->getPrice() * $qty; } - + return $bundlePrice; } - + /** * @return mixed */ private function getProductCodeOptions() { $productCode = $this->getProductCode(); + return $this->productOptions->getOptionsByCode($productCode); } - + /** * @return bool */ @@ -747,14 +840,14 @@ public function canChangeParcelCount() if ($this->getConfirmedAt()) { return false; } - + if ($this->getShippingAddress()->getCountryId() != 'NL') { return false; } - + return true; } - + /** * @return \DateTime|null */ @@ -765,7 +858,7 @@ private function getDeliveryDateByOrder() if (!$deliveryDate) { return null; } - + /** * Delivery_date => '2017-11-09 01:00:00' * When not created with \DateTime the timezoneInterface will return it like '2015-01-01 01:00:00' @@ -775,22 +868,4 @@ private function getDeliveryDateByOrder() // @codingStandardsIgnoreLine return new \DateTime($deliveryDate); } - - /** - * @param $value - * - * @return $this - */ - public function setConfirmed($value) - { - return $this->setData(static::FIELD_CONFIRMED, $value); - } - - /** - * @return mixed - */ - public function getConfirmed() - { - return $this->getData(static::FIELD_CONFIRMED); - } } diff --git a/Service/Shipment/Data.php b/Service/Shipment/Data.php index 6ef0cfcfb..cfe032c42 100644 --- a/Service/Shipment/Data.php +++ b/Service/Shipment/Data.php @@ -123,8 +123,9 @@ private function getDefaultShipmentData(ShipmentInterface $shipment, $address, $ ) ], 'DeliveryDate' => $shipment->getDeliveryDateFormatted(), - 'DownPartnerID' => $shipment->getPgRetailNetworkId(), - 'DownPartnerLocation' => $shipment->getPgLocationCode(), + 'DownPartnerID' => $shipment->getDownpartnerId(), + 'DownPartnerLocation' => $shipment->getDownpartnerLocation(), + 'DownPartnerBarcode' => $shipment->getDownpartnerBarcode(), 'ProductCodeDelivery' => $shipment->getProductCode(), 'Reference' => $this->labelAndPackingslipOptions->getReference($shipment->getShipment()) ]; diff --git a/Service/Shipment/Labelling/GenerateAbstract.php b/Service/Shipment/Labelling/GenerateAbstract.php index 0b77b8ecc..4a0c2f3d5 100644 --- a/Service/Shipment/Labelling/GenerateAbstract.php +++ b/Service/Shipment/Labelling/GenerateAbstract.php @@ -29,97 +29,84 @@ * @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\Labelling; use TIG\PostNL\Api\Data\ShipmentInterface; -use TIG\PostNL\Model\Shipment; use TIG\PostNL\Api\Data\ShipmentLabelInterface; use TIG\PostNL\Api\ShipmentLabelRepositoryInterface; use TIG\PostNL\Api\ShipmentRepositoryInterface; use TIG\PostNL\Exception as PostNLException; use TIG\PostNL\Helper\Data; use TIG\PostNL\Logging\Log; +use TIG\PostNL\Model\Shipment; use TIG\PostNL\Model\ShipmentLabelFactory; -use TIG\PostNL\Service\Converter\CanaryIslandToIC; use TIG\PostNL\Webservices\Endpoints\Labelling; use TIG\PostNL\Webservices\Endpoints\LabellingWithoutConfirm; -// @codingStandardsIgnoreFile abstract class GenerateAbstract { /** * @var Labelling|LabellingWithoutConfirm */ - // @codingStandardsIgnoreLine - protected $labelService; - + public $labelService; + /** * @var Log */ - //@codingStandardsIgnoreLine - protected $logger; - + private $logger; + /** * @var ShipmentLabelFactory */ - //@codingStandardsIgnoreLine - protected $shipmentLabelFactory; - + private $shipmentLabelFactory; + /** * @var ShipmentRepositoryInterface */ - //@codingStandardsIgnoreLine - protected $shipmentRepository; - + private $shipmentRepository; + /** * @var ShipmentLabelRepositoryInterface */ - //@codingStandardsIgnoreLine - protected $shipmentLabelRepository; - + private $shipmentLabelRepository; + /** * @var string */ - //@codingStandardsIgnoreLine - protected $date; - + private $date; + /** * @var Handler */ - //@codingStandardsIgnoreLine - protected $handler; - - /** - * @var CanaryIslandToIC - */ - protected $canaryConverter; - + private $handler; + /** - * @param Data $helper - * @param ShipmentLabelFactory $shipmentLabelFactory - * @param ShipmentLabelRepositoryInterface $shipmentLabelRepository - * @param ShipmentRepositoryInterface $shipmentRepository - * @param Log $logger - * @param Handler $handler - * @param CanaryIslandToIC $canaryConverter + * GenerateAbstract constructor. + * + * @param \TIG\PostNL\Helper\Data $helper + * @param \TIG\PostNL\Model\ShipmentLabelFactory $shipmentLabelFactory + * @param \TIG\PostNL\Api\ShipmentLabelRepositoryInterface $shipmentLabelRepository + * @param \TIG\PostNL\Api\ShipmentRepositoryInterface $shipmentRepository + * @param \TIG\PostNL\Logging\Log $logger + * @param \TIG\PostNL\Service\Shipment\Labelling\Handler $handler */ public function __construct( Data $helper, + Handler $handler, + Log $logger, ShipmentLabelFactory $shipmentLabelFactory, ShipmentLabelRepositoryInterface $shipmentLabelRepository, - ShipmentRepositoryInterface $shipmentRepository, - Log $logger, - Handler $handler, - CanaryIslandToIC $canaryConverter + ShipmentRepositoryInterface $shipmentRepository ) { - $this->logger = $logger; - $this->date = $helper->getDate(); - $this->shipmentRepository = $shipmentRepository; - $this->shipmentLabelFactory = $shipmentLabelFactory; + $this->handler = $handler; + $this->logger = $logger; + $this->shipmentLabelFactory = $shipmentLabelFactory; $this->shipmentLabelRepository = $shipmentLabelRepository; - $this->handler = $handler; + $this->shipmentRepository = $shipmentRepository; + $this->date = $helper->getDate(); } - + /** * @param ShipmentInterface $shipment * @param $currentShipmentNumber @@ -133,67 +120,87 @@ public function getLabel(ShipmentInterface $shipment, $currentShipmentNumber, $c $responseShipments = $this->callEndpoint($shipment, $currentShipmentNumber); } catch (\Exception $exception) { $this->logger->debug($exception->getMessage()); + return null; } - + + if ($responseShipments) { + $this->saveDownpartnerData($shipment, $responseShipments); + } + $labelModels = $this->handleLabels($shipment, $responseShipments, $currentShipmentNumber); - + if ($confirm) { $shipment->setConfirmedAt($this->date); $shipment->setConfirmed(true); $this->shipmentRepository->save($shipment); } - + return $labelModels; } - + /** - * @param ShipmentInterface $postnlShipment - * @param $currentShipmentNumber + * @param \TIG\PostNL\Api\Data\ShipmentInterface $shipment + * @param $response + */ + private function saveDownpartnerData(ShipmentInterface $shipment, $response) + { + $downPartnerBarcode = $response[0]->DownPartnerBarcode; + $downPartnerId = $response[0]->DownPartnerID; + $downPartnerLocation = $response[0]->DownPartnerLocation; + + $shipment->setDownpartnerBarcode($downPartnerBarcode); + $shipment->setDownpartnerId($downPartnerId); + $shipment->setDownpartnerLocation($downPartnerLocation); + $this->shipmentRepository->save($shipment); + } + + /** + * @param \TIG\PostNL\Api\Data\ShipmentInterface $postNlShipment + * @param $currentShipmentNumber * * @return mixed - * @throws PostNLException + * @throws \Magento\Framework\Webapi\Exception + * @throws \TIG\PostNL\Exception */ - //@codingStandardsIgnoreLine - protected function callEndpoint(ShipmentInterface $postnlShipment, $currentShipmentNumber) + private function callEndpoint(ShipmentInterface $postNlShipment, $currentShipmentNumber) { - $this->labelService->setParameters($postnlShipment, $currentShipmentNumber); + $this->labelService->setParameters($postNlShipment, $currentShipmentNumber); $response = $this->labelService->call(); $responseShipments = null; - + if (isset($response->ResponseShipments)) { $responseShipments = $response->ResponseShipments; } - + if (!is_object($response) || !isset($responseShipments->ResponseShipment)) { throw new PostNLException(sprintf('Invalid generateLabel response: %1', var_export($response, true))); } - + return $responseShipments->ResponseShipment; } - + /** * @param $shipment - * @param $responsShipments + * @param $responseShipments * @param $currentShipmentNumber * * @return ShipmentLabelInterface[] */ - //@codingStandardsIgnoreLine - protected function handleLabels($shipment, $responsShipments, $currentShipmentNumber) + private function handleLabels($shipment, $responseShipments, $currentShipmentNumber) { $labelModels = []; - foreach ($responsShipments as $labelItem) { + foreach ($responseShipments as $labelItem) { $labelModels = array_merge( $labelModels, $this->getLabelModels($labelItem, $shipment, $currentShipmentNumber) ); $currentShipmentNumber++; } - + return $labelModels; } - + /** * @param $labelItem * @param $shipment @@ -206,17 +213,17 @@ private function getLabelModels($labelItem, ShipmentInterface $shipment, $curren { $labelModels = []; $labelItemHandle = $this->handler->handle($shipment, $labelItem->Labels->Label); - + foreach ($labelItemHandle['labels'] as $Label) { $labelModel = $this->save($shipment, $currentShipmentNumber, $Label, $labelItemHandle['type'], $labelItem->ProductCodeDelivery); $labelModels[] = $labelModel; $this->shipmentLabelRepository->save($labelModel); } - + return $labelModels; } //@codingStandardsIgnoreEnd - + /** * @param ShipmentInterface|Shipment $shipment * @param int $number @@ -235,7 +242,7 @@ public function save(ShipmentInterface $shipment, $number, $label, $type, $produ $labelModel->setLabel(base64_encode($label)); $labelModel->setType($type ?: ShipmentLabelInterface::BARCODE_TYPE_LABEL); $labelModel->setProductCode($productCode); - + return $labelModel; } } From 208d40aebc0783b44bd7f1d3a4d93d897ca1a00b Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 10:17:40 +0100 Subject: [PATCH 14/26] Minor re-factor, because CanaryIslandToIC wasn't used. --- .../Labelling/Generate/WithConfirm.php | 24 ++++++++++++------- .../Labelling/Generate/WithoutConfirm.php | 24 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Service/Shipment/Labelling/Generate/WithConfirm.php b/Service/Shipment/Labelling/Generate/WithConfirm.php index 504749423..c8f64a996 100644 --- a/Service/Shipment/Labelling/Generate/WithConfirm.php +++ b/Service/Shipment/Labelling/Generate/WithConfirm.php @@ -31,7 +31,6 @@ */ namespace TIG\PostNL\Service\Shipment\Labelling\Generate; -use TIG\PostNL\Service\Converter\CanaryIslandToIC; use TIG\PostNL\Service\Shipment\Labelling\GenerateAbstract; use TIG\PostNL\Helper\Data; use TIG\PostNL\Logging\Log; @@ -44,24 +43,33 @@ class WithConfirm extends GenerateAbstract { + /** + * WithConfirm constructor. + * + * @param \TIG\PostNL\Helper\Data $helper + * @param \TIG\PostNL\Service\Shipment\Labelling\Handler $handler + * @param \TIG\PostNL\Logging\Log $logger + * @param \TIG\PostNL\Model\ShipmentLabelFactory $shipmentLabelFactory + * @param \TIG\PostNL\Api\ShipmentLabelRepositoryInterface $shipmentLabelRepository + * @param \TIG\PostNL\Api\ShipmentRepositoryInterface $shipmentRepository + * @param \TIG\PostNL\Webservices\Endpoints\Labelling $labelling + */ public function __construct( Data $helper, + Handler $handler, + Log $logger, ShipmentLabelFactory $shipmentLabelFactory, ShipmentLabelRepositoryInterface $shipmentLabelRepository, ShipmentRepositoryInterface $shipmentRepository, - Log $logger, - Handler $handler, - CanaryIslandToIC $canaryConverter, Labelling $labelling ) { parent::__construct( $helper, + $handler, + $logger, $shipmentLabelFactory, $shipmentLabelRepository, - $shipmentRepository, - $logger, - $handler, - $canaryConverter + $shipmentRepository ); $this->labelService = $labelling; diff --git a/Service/Shipment/Labelling/Generate/WithoutConfirm.php b/Service/Shipment/Labelling/Generate/WithoutConfirm.php index df2dcdf87..ecbcd0fa9 100644 --- a/Service/Shipment/Labelling/Generate/WithoutConfirm.php +++ b/Service/Shipment/Labelling/Generate/WithoutConfirm.php @@ -31,7 +31,6 @@ */ namespace TIG\PostNL\Service\Shipment\Labelling\Generate; -use TIG\PostNL\Service\Converter\CanaryIslandToIC; use TIG\PostNL\Service\Shipment\Labelling\GenerateAbstract; use TIG\PostNL\Helper\Data; use TIG\PostNL\Logging\Log; @@ -44,24 +43,33 @@ class WithoutConfirm extends GenerateAbstract { + /** + * WithoutConfirm constructor. + * + * @param \TIG\PostNL\Helper\Data $helper + * @param \TIG\PostNL\Service\Shipment\Labelling\Handler $handler + * @param \TIG\PostNL\Logging\Log $logger + * @param \TIG\PostNL\Model\ShipmentLabelFactory $shipmentLabelFactory + * @param \TIG\PostNL\Api\ShipmentLabelRepositoryInterface $shipmentLabelRepository + * @param \TIG\PostNL\Api\ShipmentRepositoryInterface $shipmentRepository + * @param \TIG\PostNL\Webservices\Endpoints\LabellingWithoutConfirm $labelling + */ public function __construct( Data $helper, + Handler $handler, + Log $logger, ShipmentLabelFactory $shipmentLabelFactory, ShipmentLabelRepositoryInterface $shipmentLabelRepository, ShipmentRepositoryInterface $shipmentRepository, - Log $logger, - Handler $handler, - CanaryIslandToIC $canaryConverter, LabellingWithoutConfirm $labelling ) { parent::__construct( $helper, + $handler, + $logger, $shipmentLabelFactory, $shipmentLabelRepository, - $shipmentRepository, - $logger, - $handler, - $canaryConverter + $shipmentRepository ); $this->labelService = $labelling; From 9cd70348df4724b7527e532acb335f77a9136aa2 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 11:37:38 +0100 Subject: [PATCH 15/26] POSTNLM2-769: If SAM returns different product code during label generation, overwrite it in Shipment-table. --- Service/Shipment/Labelling/GenerateAbstract.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Service/Shipment/Labelling/GenerateAbstract.php b/Service/Shipment/Labelling/GenerateAbstract.php index 4a0c2f3d5..92199e243 100644 --- a/Service/Shipment/Labelling/GenerateAbstract.php +++ b/Service/Shipment/Labelling/GenerateAbstract.php @@ -242,6 +242,15 @@ public function save(ShipmentInterface $shipment, $number, $label, $type, $produ $labelModel->setLabel(base64_encode($label)); $labelModel->setType($type ?: ShipmentLabelInterface::BARCODE_TYPE_LABEL); $labelModel->setProductCode($productCode); + + /** + * If SAM returned different product code during generation, override + * it in PostNL Shipment table. + */ + if ($productCode !== $shipment->getProductCode()) { + $shipment->setProductCode($productCode); + $this->shipmentRepository->save($shipment); + } return $labelModel; } From 70c84935b3b45dd625a1628958371da22ed00cfd Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 11:48:48 +0100 Subject: [PATCH 16/26] POSTNLM2-769: Moved overwrite action outside of foreach-loop. --- .../Shipment/Labelling/GenerateAbstract.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Service/Shipment/Labelling/GenerateAbstract.php b/Service/Shipment/Labelling/GenerateAbstract.php index 92199e243..03af90022 100644 --- a/Service/Shipment/Labelling/GenerateAbstract.php +++ b/Service/Shipment/Labelling/GenerateAbstract.php @@ -219,6 +219,15 @@ private function getLabelModels($labelItem, ShipmentInterface $shipment, $curren $labelModels[] = $labelModel; $this->shipmentLabelRepository->save($labelModel); } + + /** + * If SAM returned different product code during generation, override + * it in PostNL Shipment table. + */ + if ($labelItem->ProductCodeDelivery !== $shipment->getProductCode()) { + $shipment->setProductCode($labelItem->ProductCodeDelivery); + $this->shipmentRepository->save($shipment); + } return $labelModels; } @@ -242,15 +251,6 @@ public function save(ShipmentInterface $shipment, $number, $label, $type, $produ $labelModel->setLabel(base64_encode($label)); $labelModel->setType($type ?: ShipmentLabelInterface::BARCODE_TYPE_LABEL); $labelModel->setProductCode($productCode); - - /** - * If SAM returned different product code during generation, override - * it in PostNL Shipment table. - */ - if ($productCode !== $shipment->getProductCode()) { - $shipment->setProductCode($productCode); - $this->shipmentRepository->save($shipment); - } return $labelModel; } From 17c42f208b1d600dc61f372288f5dbc02189ec77 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 12:39:20 +0100 Subject: [PATCH 17/26] POSTNLM2-769: Modified test to work with new Downpartner Data. --- Test/Unit/Service/Shipment/DataTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/Unit/Service/Shipment/DataTest.php b/Test/Unit/Service/Shipment/DataTest.php index ecdca7a44..81936b046 100644 --- a/Test/Unit/Service/Shipment/DataTest.php +++ b/Test/Unit/Service/Shipment/DataTest.php @@ -197,8 +197,8 @@ private function getShipmentData($addresses, $contact) $this->mockFunction($this->shipmentMock, 'getMainBarcode', $shipmentData['Barcode']); $this->mockFunction($this->shipmentMock, 'getTotalWeight', $shipmentData['Dimension']['Weight']); $this->mockFunction($this->shipmentMock, 'getDeliveryDateFormatted', $shipmentData['DeliveryDate']); - $this->mockFunction($this->shipmentMock, 'getPgRetailNetworkId', $shipmentData['DownPartnerID']); - $this->mockFunction($this->shipmentMock, 'getPgLocationCode', $shipmentData['DownPartnerLocation']); + $this->mockFunction($this->shipmentMock, 'getDownpartnerId', $shipmentData['DownPartnerID']); + $this->mockFunction($this->shipmentMock, 'getDownpartnerLocation', $shipmentData['DownPartnerLocation']); $this->mockFunction($this->shipmentMock, 'getProductCode', $shipmentData['ProductCodeDelivery']); $this->mockFunction($this->packingslipOptionsMock, 'getReference', $shipmentData['Reference']); From 88aa0aea98b059414cdc8f06b34b3de2c479cecb Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 13:07:32 +0100 Subject: [PATCH 18/26] POSTNLM2-769: Re-factored due to Calisthenics requirements. --- .../Labelling/Generate/WithConfirm.php | 7 ++- .../Labelling/Generate/WithoutConfirm.php | 7 ++- .../Shipment/Labelling/GenerateAbstract.php | 49 ++++++++----------- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Service/Shipment/Labelling/Generate/WithConfirm.php b/Service/Shipment/Labelling/Generate/WithConfirm.php index c8f64a996..baec54d8f 100644 --- a/Service/Shipment/Labelling/Generate/WithConfirm.php +++ b/Service/Shipment/Labelling/Generate/WithConfirm.php @@ -43,6 +43,9 @@ class WithConfirm extends GenerateAbstract { + /** @var \TIG\PostNL\Webservices\Endpoints\Labelling $labelling */ + private $labelling; + /** * WithConfirm constructor. * @@ -72,7 +75,7 @@ public function __construct( $shipmentRepository ); - $this->labelService = $labelling; + $this->labelling = $labelling; } /** @@ -83,6 +86,8 @@ public function __construct( */ public function get(ShipmentInterface $shipment, $currentNumber) { + $this->setLabelService($this->labelling); + return $this->getLabel($shipment, $currentNumber, true); } } diff --git a/Service/Shipment/Labelling/Generate/WithoutConfirm.php b/Service/Shipment/Labelling/Generate/WithoutConfirm.php index ecbcd0fa9..528317e39 100644 --- a/Service/Shipment/Labelling/Generate/WithoutConfirm.php +++ b/Service/Shipment/Labelling/Generate/WithoutConfirm.php @@ -43,6 +43,9 @@ class WithoutConfirm extends GenerateAbstract { + /** @var \TIG\PostNL\Webservices\Endpoints\LabellingWithoutConfirm $labelling */ + private $labelling; + /** * WithoutConfirm constructor. * @@ -72,7 +75,7 @@ public function __construct( $shipmentRepository ); - $this->labelService = $labelling; + $this->labelling = $labelling; } /** @@ -83,6 +86,8 @@ public function __construct( */ public function get(ShipmentInterface $shipment, $currentNumber) { + $this->setLabelService($this->labelling); + return $this->getLabel($shipment, $currentNumber, false); } } diff --git a/Service/Shipment/Labelling/GenerateAbstract.php b/Service/Shipment/Labelling/GenerateAbstract.php index 03af90022..90540fa3e 100644 --- a/Service/Shipment/Labelling/GenerateAbstract.php +++ b/Service/Shipment/Labelling/GenerateAbstract.php @@ -41,44 +41,29 @@ use TIG\PostNL\Logging\Log; use TIG\PostNL\Model\Shipment; use TIG\PostNL\Model\ShipmentLabelFactory; -use TIG\PostNL\Webservices\Endpoints\Labelling; -use TIG\PostNL\Webservices\Endpoints\LabellingWithoutConfirm; +// @codingStandardsIgnoreFile abstract class GenerateAbstract { - /** - * @var Labelling|LabellingWithoutConfirm - */ - public $labelService; + /** @var $labelling */ + private $labelling; - /** - * @var Log - */ + /** @var \TIG\PostNL\Logging\Log $logger */ private $logger; - /** - * @var ShipmentLabelFactory - */ + /** @var \TIG\PostNL\Model\ShipmentLabelFactory $shipmentLabelFactory */ private $shipmentLabelFactory; - /** - * @var ShipmentRepositoryInterface - */ + /** @var \TIG\PostNL\Api\ShipmentRepositoryInterface $shipmentRepository */ private $shipmentRepository; - /** - * @var ShipmentLabelRepositoryInterface - */ + /** @var \TIG\PostNL\Api\ShipmentLabelRepositoryInterface $shipmentLabelRepository */ private $shipmentLabelRepository; - /** - * @var string - */ + /** @var string $date */ private $date; - /** - * @var Handler - */ + /** @var \TIG\PostNL\Service\Shipment\Labelling\Handler $handler */ private $handler; /** @@ -165,8 +150,8 @@ private function saveDownpartnerData(ShipmentInterface $shipment, $response) */ private function callEndpoint(ShipmentInterface $postNlShipment, $currentShipmentNumber) { - $this->labelService->setParameters($postNlShipment, $currentShipmentNumber); - $response = $this->labelService->call(); + $this->labelling->setParameters($postNlShipment, $currentShipmentNumber); + $response = $this->labelling->call(); $responseShipments = null; if (isset($response->ResponseShipments)) { @@ -180,6 +165,14 @@ private function callEndpoint(ShipmentInterface $postNlShipment, $currentShipmen return $responseShipments->ResponseShipment; } + /** + * @param $labelService + */ + public function setLabelService($labelService) + { + $this->labelling = $labelService; + } + /** * @param $shipment * @param $responseShipments @@ -208,7 +201,6 @@ private function handleLabels($shipment, $responseShipments, $currentShipmentNum * * @return array */ - //@codingStandardsIgnoreStart private function getLabelModels($labelItem, ShipmentInterface $shipment, $currentShipmentNumber) { $labelModels = []; @@ -219,7 +211,7 @@ private function getLabelModels($labelItem, ShipmentInterface $shipment, $curren $labelModels[] = $labelModel; $this->shipmentLabelRepository->save($labelModel); } - + /** * If SAM returned different product code during generation, override * it in PostNL Shipment table. @@ -231,7 +223,6 @@ private function getLabelModels($labelItem, ShipmentInterface $shipment, $curren return $labelModels; } - //@codingStandardsIgnoreEnd /** * @param ShipmentInterface|Shipment $shipment From d0954fc0b84d2d3622d75d9fb30fa8246848cf87 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 13:10:48 +0100 Subject: [PATCH 19/26] POSTNLM2-769: Fixed phpdoc --- Service/Shipment/Labelling/GenerateAbstract.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Service/Shipment/Labelling/GenerateAbstract.php b/Service/Shipment/Labelling/GenerateAbstract.php index 90540fa3e..5b81cdf69 100644 --- a/Service/Shipment/Labelling/GenerateAbstract.php +++ b/Service/Shipment/Labelling/GenerateAbstract.php @@ -45,7 +45,10 @@ // @codingStandardsIgnoreFile abstract class GenerateAbstract { - /** @var $labelling */ + /** + * @var \TIG\PostNL\Webservices\Endpoints\Labelling|\TIG\PostNL\Webservices\Endpoints\LabellingWithoutConfirm + * $labelling + */ private $labelling; /** @var \TIG\PostNL\Logging\Log $logger */ From d5820eb63c42738d825cc553b6cb0f4017467d12 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 13:14:23 +0100 Subject: [PATCH 20/26] POSTNLM2-769: Fixed phpdoc --- Service/Shipment/Labelling/GenerateAbstract.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Service/Shipment/Labelling/GenerateAbstract.php b/Service/Shipment/Labelling/GenerateAbstract.php index 5b81cdf69..70bce000e 100644 --- a/Service/Shipment/Labelling/GenerateAbstract.php +++ b/Service/Shipment/Labelling/GenerateAbstract.php @@ -51,24 +51,24 @@ abstract class GenerateAbstract */ private $labelling; + /** @var \TIG\PostNL\Service\Shipment\Labelling\Handler $handler */ + private $handler; + /** @var \TIG\PostNL\Logging\Log $logger */ private $logger; /** @var \TIG\PostNL\Model\ShipmentLabelFactory $shipmentLabelFactory */ private $shipmentLabelFactory; - /** @var \TIG\PostNL\Api\ShipmentRepositoryInterface $shipmentRepository */ - private $shipmentRepository; - /** @var \TIG\PostNL\Api\ShipmentLabelRepositoryInterface $shipmentLabelRepository */ private $shipmentLabelRepository; + /** @var \TIG\PostNL\Api\ShipmentRepositoryInterface $shipmentRepository */ + private $shipmentRepository; + /** @var string $date */ private $date; - /** @var \TIG\PostNL\Service\Shipment\Labelling\Handler $handler */ - private $handler; - /** * GenerateAbstract constructor. * From 44d139046da65c89a59ce3fa44c4825d9ce3d963 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 13:49:55 +0100 Subject: [PATCH 21/26] POSTNLM2-769: Removed CountTest because it's irrelevant. --- .../Service/Parcel/Order/CountTest.php | 93 ------------------- 1 file changed, 93 deletions(-) delete mode 100644 Test/Integration/Service/Parcel/Order/CountTest.php diff --git a/Test/Integration/Service/Parcel/Order/CountTest.php b/Test/Integration/Service/Parcel/Order/CountTest.php deleted file mode 100644 index 586561379..000000000 --- a/Test/Integration/Service/Parcel/Order/CountTest.php +++ /dev/null @@ -1,93 +0,0 @@ - [true, 2], - 'Extra@Home disabled' => [false, 3] // 3 because of the weight of 60kg - ]; - } - - /** - * @param $enabled - * @param $expected - * - * @dataProvider getDataProvider - */ - public function testGetWithExtraAtHomeOrder($enabled, $expected) - { - require __DIR__.'/../../../../Fixtures/Extra_at_home/ExtraAtHomeOrder.php'; - - $shippingOptions = $this->getMockBuilder(ShippingOptions::class); - $shippingOptions->disableOriginalConstructor(); - $shippingOptions = $shippingOptions->getMock(); - - $this->objectManager->configure([ - 'preferences' => [ - ShippingOptions::class => get_class($shippingOptions) - ] - ]); - - $shippingOptions = $this->objectManager->get(ShippingOptions::class); - $shippingOptions->method('isExtraAtHomeActive')->willReturn($enabled); - - /** @var \Magento\Sales\Model\Order $order */ - $order = $this->getOrder(); - $result = $this->getInstance()->get($order); - - $this->assertEquals($expected, $result); - } - - /** - * @return \Magento\Framework\DataObject|\Magento\Sales\Model\Order - */ - private function getOrder() - { - /** @var Collection $orderCollection */ - $orderCollection = $this->getObject(Collection::class); - $orderCollection->addFieldToFilter('customer_email', 'customer@tig.nl'); - - return $orderCollection->getFirstItem(); - } -} \ No newline at end of file From 25f58c8bb5eeb7f0f021c9402e047b1d186979e8 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Thu, 21 Mar 2019 14:36:52 +0100 Subject: [PATCH 22/26] [IMPROVE UX] If label isn't generated yet, show 'Generate Label' instead of 'Print Label' + minor re-factor. --- Block/Adminhtml/Shipment/View.php | 43 +++++++++---------------------- i18n/en_US.csv | 1 + i18n/nl_NL.csv | 1 + 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/Block/Adminhtml/Shipment/View.php b/Block/Adminhtml/Shipment/View.php index 653de658d..6651b0656 100644 --- a/Block/Adminhtml/Shipment/View.php +++ b/Block/Adminhtml/Shipment/View.php @@ -43,29 +43,13 @@ // @codingStandardsIgnoreFile class View extends MagentoView { - /** - * @var string - */ - private $printRoute = 'postnl/shipment/confirmAndPrintShippingLabel'; - - /** - * @var string - */ - private $printLabel = 'PostNL - Confirm And Print Shipment Label'; - - /** - * @var PostNLShipmentRepository - */ + /** @var \TIG\PostNL\Model\ShipmentRepository $postNLShipmentRepository */ private $postNLShipmentRepository; - /** - * @var SearchCriteriaBuilder - */ + /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder */ private $searchCriteriaBuilder; - /** - * @var ValidAddress - */ + /** @var \TIG\PostNL\Config\Validator\ValidAddress $validAddress */ private $validAddress; /** @@ -90,8 +74,7 @@ public function __construct( parent::__construct($context, $registry, $data); } - - // @codingStandardsIgnoreLine + protected function _construct() { parent::_construct(); @@ -120,7 +103,6 @@ protected function _construct() private function processButtons() { $this->buttonList->remove('print'); - //@codingStandardsIgnoreLine $this->buttonList->update('save', 'label', __('Send Shipment Email')); $this->setPostNLPrintLabelButton(); $this->setPostNLPrintLabelButtonData(); @@ -136,8 +118,7 @@ private function setPostNLPrintLabelButton() $this->buttonList->add( 'postnl_print', [ - // @codingStandardsIgnoreLine - 'label' => __($this->printLabel), + 'label' => __('PostNL - Confirm And Print Shipment Label'), 'class' => 'save primary', 'onclick' => 'download(\'' .$this->getLabelUrl() .'\')' ] @@ -149,7 +130,6 @@ private function setPostNLPrintLabelButton() */ private function setPostNLCancelConfirmButton() { - /** @codingStandardsIgnoreStart */ $this->buttonList->add( 'postnl_cancel_confirm', [ @@ -164,16 +144,17 @@ private function setPostNLCancelConfirmButton() ) . '\', \'' . $this->getCancelConfirmationUrl() . '\')' ] ); - /** @codingStandardsIgnoreEnd */ } private function setPostNLPrintLabelWithoutConfirmButton() { + $postNLShipment = $this->getPostNLShipment(); + $mainBarcode = $postNLShipment->getMainBarcode(); + $this->buttonList->add( 'postnl_print_without_confirm', [ - // @codingStandardsIgnoreLine - 'label' => __('PostNL - Print Label'), + 'label' => $mainBarcode ? __('PostNL - Print Label') : __('PostNL - Generate Label'), 'class' => 'save primary', 'onclick' => 'download(\'' .$this->getLabelWithoutConfirmUrl() .'\')' ] @@ -185,7 +166,6 @@ private function setPostNLPrintPackingslipButton() $this->buttonList->add( 'postnl_print_packingslip', [ - // @codingStandardsIgnoreLine 'label' => __('PostNL - Print Packingslip'), 'class' => 'save primary', 'onclick' => 'download(\'' .$this->getPackingslipUrl() .'\')' @@ -198,7 +178,6 @@ private function setPostNLConfirmButton() $this->buttonList->add( 'postnl_confirm_shipment', [ - // @codingStandardsIgnoreLine 'label' => __('PostNL - Confirm'), 'class' => 'save primary', 'onclick' => 'setLocation(\'' . $this->getConfirmUrl() . '\')', @@ -229,7 +208,9 @@ private function setPostNLPrintLabelButtonData() */ private function getLabelUrl() { - return $this->getUrl($this->printRoute, ['shipment_id' => $this->getShipment()->getId()]); + return $this->getUrl( + 'postnl/shipment/confirmAndPrintShippingLabel', + ['shipment_id' => $this->getShipment()->getId()]); } /** diff --git a/i18n/en_US.csv b/i18n/en_US.csv index ca71eba5a..1d5797272 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -176,6 +176,7 @@ Percent,Percent "PostNL - Cancel Confirmation","PostNL - Cancel Confirmation" "Are you sure that you wish to reset the confirmation status of this shipment? You will need to confirm this shipment with PostNL again before you can send it. This action will remove all barcodes and labels associated with this shipment. You can not undo this action.","Are you sure that you wish to reset the confirmation status of this shipment? You will need to confirm this shipment with PostNL again before you can send it. This action will remove all barcodes and labels associated with this shipment. You can not undo this action." "PostNL - Print label","PostNL - Print label" +"PostNL - Generate Label","PostNL - Generate Label" "Default postoffice early pickup option","Default postoffice early pickup option" "Post office delivery","Post office delivery" "Post office early delivery","Post office early delivery" diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index 8ac335636..5d8716c33 100644 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -193,6 +193,7 @@ Percent,Percentage "PostNL - Cancel Confirmation","PostNL - Voormelding verwijderen" "Are you sure that you wish to reset the confirmation status of this shipment? You will need to confirm this shipment with PostNL again before you can send it. This action will remove all barcodes and labels associated with this shipment. You can not undo this action.","Weet je zeker dat je de voormelding van deze verzending wilt wijzgen? De verzending zal opnieuw voorgemeld moeten worden voordat je deze alsnog kunt verzenden. Deze actie verwijdert alle barcodes en labels die bij deze verzending horen. Dit kan niet ongedaan worden gemaakt." "PostNL - Print label","PostNL - Print label" +"PostNL - Generate Label","PostNL - Genereer Label" "Default postoffice early pickup option","Standaard ophalen bij PostNL locatie extra vroeg optie" "In order to use this extension you need to be a contract customer of PostNL. If you are not a customer of PostNL, you can register yourself here.","Om deze extensie te kunnen gebruiken dient u een contract met PostNL af te sluiten. Indien u geen klant bent van PostNL dan kunt u zichzelf hier aanmelden." "You will then receive all necessary information in order to configure the extension. If you cannot find the email containing this information, please contact PostNL support at 058-2333343.","U ontvangt de benodigde informatie om deze extensie te configureren. Indien u deze e-mail met informatie niet heeft ontvangen, neem dan contact met PostNL support op 058-2333343." From 22360fc282b9d3404bc0760d35d0ad2190de77e6 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 27 Mar 2019 10:53:02 +0100 Subject: [PATCH 23/26] Upped version to 1.7.4 --- Block/Adminhtml/Config/Support/SupportTab.php | 2 +- composer.json | 2 +- etc/module.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Block/Adminhtml/Config/Support/SupportTab.php b/Block/Adminhtml/Config/Support/SupportTab.php index 6027e9b81..8b18a1b5b 100644 --- a/Block/Adminhtml/Config/Support/SupportTab.php +++ b/Block/Adminhtml/Config/Support/SupportTab.php @@ -38,7 +38,7 @@ class SupportTab extends Template implements RendererInterface { - const POSTNL_VERSION = '1.7.3'; + const POSTNL_VERSION = '1.7.4'; const XPATH_SUPPORTED_MAGENTO_VERSION = 'tig_postnl/supported_magento_version'; diff --git a/composer.json b/composer.json index 398f7f196..db0996dcc 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ }, "type": "magento2-module", "license": "CC-BY-NC-ND-3.0", - "version": "1.7.3", + "version": "1.7.4", "authors": [ { "name": "TIG", diff --git a/etc/module.xml b/etc/module.xml index 358d96eb2..285b7be1a 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -32,7 +32,7 @@ * --> - + From f33927888bbb0d48b844eb38a91031ef766bfc3c Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 27 Mar 2019 11:02:41 +0100 Subject: [PATCH 24/26] Upped version to 1.7.4-rc1 for compatibility with M2.1.17, M2.2.8 and M2.3.1. --- Block/Adminhtml/Config/Support/SupportTab.php | 2 +- composer.json | 6 +++--- etc/module.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Block/Adminhtml/Config/Support/SupportTab.php b/Block/Adminhtml/Config/Support/SupportTab.php index 8b18a1b5b..5ca1dfce5 100644 --- a/Block/Adminhtml/Config/Support/SupportTab.php +++ b/Block/Adminhtml/Config/Support/SupportTab.php @@ -38,7 +38,7 @@ class SupportTab extends Template implements RendererInterface { - const POSTNL_VERSION = '1.7.4'; + const POSTNL_VERSION = '1.7.4-RC1'; const XPATH_SUPPORTED_MAGENTO_VERSION = 'tig_postnl/supported_magento_version'; diff --git a/composer.json b/composer.json index db0996dcc..938bb03cd 100644 --- a/composer.json +++ b/composer.json @@ -3,13 +3,13 @@ "description": "TIG Magento 2 PostNL extension", "require": { "php": "~7.0|~7.1|~7.2", - "magento/framework": ">=100.1.0,<=100.1.16|>=101.0.0,<=101.0.7|>=102.0.0", + "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" }, "type": "magento2-module", "license": "CC-BY-NC-ND-3.0", - "version": "1.7.4", + "version": "1.7.4-RC1", "authors": [ { "name": "TIG", @@ -23,7 +23,7 @@ }, "homepage": "https://tig.nl/postnl", "keywords": ["PostNL", "Official PostNL extension", "Magento 2"], - "minimum-stability": "stable", + "minimum-stability": "RC", "autoload": { "files": [ "registration.php" diff --git a/etc/module.xml b/etc/module.xml index 285b7be1a..f6173717b 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -32,7 +32,7 @@ * --> - + From 89b692996d5e43c1e9a42541cb9708acbcd142b0 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 27 Mar 2019 11:50:51 +0100 Subject: [PATCH 25/26] Modified support addresses. --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 938bb03cd..cb6c1ce7c 100644 --- a/composer.json +++ b/composer.json @@ -13,13 +13,13 @@ "authors": [ { "name": "TIG", - "email": "servicedesk@tig.nl", + "email": "support@tig.nl", "homepage": "http://tig.nl" } ], "support": { - "email": "servicedesk@tig.nl", - "issues": "http://servicedesk.tig.nl/hc/nl/requests/new" + "email": "support@tig.nl", + "issues": "https://portal.tig.nl/" }, "homepage": "https://tig.nl/postnl", "keywords": ["PostNL", "Official PostNL extension", "Magento 2"], From 2aa96f19776391867c78f713de94c39dc5c642f0 Mon Sep 17 00:00:00 2001 From: Daan van den Bergh Date: Wed, 27 Mar 2019 11:59:24 +0100 Subject: [PATCH 26/26] Added 2.3.1 as support magento version. --- etc/config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/config.xml b/etc/config.xml index 42ecce7fc..a1ca545da 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -47,7 +47,7 @@ - 2.1.0 - 2.1.16, 2.2.0 - 2.2.7, 2.3.0 + 2.1.0 - 2.1.16, 2.2.0 - 2.2.7, 2.3.0 - 2.3.1 0 11223344