Skip to content

Commit

Permalink
Merge pull request postnl#248 from tig-nl/sprint114_hide_priority
Browse files Browse the repository at this point in the history
v1.8.0 - Candidate for release.
  • Loading branch information
tig-daanvandenbergh authored Jun 27, 2019
2 parents 5cb1141 + 9d6aac4 commit 23eff8a
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 25 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ matrix:
# PHP 7.1 is only supported in Magento 2.2.x
# PHP 7.2 is only supported in Magento 2.3.x
include:
- php: 7.0
env: MAGENTO_VERSION=2.1.16
- php: 7.0
env: MAGENTO_VERSION=2.1.17
- php: 7.0
env: MAGENTO_VERSION=2.2.7
- php: 7.1
env: MAGENTO_VERSION=2.1.18
- php: 7.0
env: MAGENTO_VERSION=2.2.8
- php: 7.1
env: MAGENTO_VERSION=2.3.0
env: MAGENTO_VERSION=2.2.9
- php: 7.1
env: MAGENTO_VERSION=2.3.1 # DI_COMPILE=true
env: MAGENTO_VERSION=2.3.1
- php: 7.2
env: MAGENTO_VERSION=2.3.2 # DI_COMPILE=true
- php: 7.2
env: MAGENTO_VERSION=2.3.1 CODE_COVERAGE=true
env: MAGENTO_VERSION=2.3.2 CODE_COVERAGE=true

before_script:
- export PATH=$PATH:$HOME/.composer/vendor/bin
Expand Down
5 changes: 5 additions & 0 deletions Controller/Adminhtml/PdfDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public function get($labels, $filename = 'ShippingLabels')
private function filterLabel($labels)
{
return array_filter($labels, function ($label) {

if (is_array($label)) {
return false;
}

/** @var ShipmentLabelInterface $label */
if (strtoupper($label->getType()) == ProductInfo::SHIPMENT_TYPE_GP) {
$this->filteredLabels[] = $label->getParentId();
Expand Down
4 changes: 2 additions & 2 deletions Helper/DeliveryOptions/OrderParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ private function addExtraToAddress($params)

$params['address']['Name'] = isset($params['name']) ? $params['name'] : '';

if (!isset($params['customerData'])) {
if ($params['type'] == ProductInfo::TYPE_PICKUP && !isset($params['customerData'])) {
throw new PostnlException(
__('Missing required parameters: customerData')
);
}

$params['address']['customer'] = $params['customerData'];
$params['address']['customer'] = isset($params['customerData']) ? $params['customerData'] : $params['address'];

return $params['address'];
}
Expand Down
8 changes: 7 additions & 1 deletion Service/Shipment/Label/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class Validator
* @var array
*/
private $errors = [];

/**
* @var bool
*/
private $priorityError = false;

/**
* Validator constructor.
Expand Down Expand Up @@ -165,9 +170,10 @@ private function validatePriority(ShipmentInterface $shipment)
}

/** We want to show this notification for every Priority Shipment */
if ($isPriority) {
if ($isPriority && $this->priorityError == false) {
// @codingStandardsIgnoreLine
$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.');
$this->priorityError = true;
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion Service/Shipment/Packingslip/MergeWithLabels.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function merge($shipmentId, $packingslip, $mergeFirstLabel = false, $conf
return $packingslip;
}

if (isset($labels['errors'])) {
if (isset($labels['errors']) && count($labels['errors']) > 0) {
return $labels['errors'];
}

Expand Down
4 changes: 3 additions & 1 deletion Service/Timeframe/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public function get($countryId = 'NL')
$deliveryTimeframesOptions[] = self::EVENING_DELIVERY_OPTION;
}

if ($this->shippingOptions->isSundayDeliveryActive() && $this->hasSaturdayAsShippingDay()) {
// Sunday Delivery is only available for the Netherlands
if ($this->shippingOptions->isSundayDeliveryActive()
&& $this->hasSaturdayAsShippingDay() && $countryId == 'NL') {
$deliveryTimeframesOptions[] = self::SUNDAY_DELIVERY_OPTION;
}

Expand Down
35 changes: 25 additions & 10 deletions Test/Unit/Webservices/Endpoints/SentDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\Test\Unit\Webservices\Endpoints;

use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function theParametersAreSetCorrectlyProvider()
['country' => 'DE', 'postcode' => '10179', 'delivery_date' => null],
['country' => 'NL', 'postcode' => '2132WT', 'delivery_date' => '19-11-2016'],
],
'Reverse date' => [
'Reverse date' => [
['country' => 'NL', 'postcode' => '1014 BA', 'delivery_date' => '2016-11-19'],
['country' => 'NL', 'postcode' => '1014BA', 'delivery_date' => '19-11-2016'],
],
Expand All @@ -89,10 +90,12 @@ public function testTheParametersAreSetCorrectly($input, $expected)

$orderMock = $this->getMock(OrderInterface::class);
$this->mockFunction($orderMock, 'getDeliveryDate', $input['delivery_date']);
$falbackMock = $this->deliveryDateFallbackMock();
$fallbackMock = $this->deliveryDateFallbackMock();
$optionsMock = $this->optionsMock();

$instance = $this->getInstance([
'dateFallback' => $falbackMock
'dateFallback' => $fallbackMock,
'timeframeOptions' => $optionsMock
]);
$instance->setParameters($address, 1, $orderMock);

Expand All @@ -103,20 +106,32 @@ public function testTheParametersAreSetCorrectly($input, $expected)
$this->assertEquals($expected['delivery_date'], $result['GetSentDate']['DeliveryDate']);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function optionsMock()
{
$optionsMock = $this->getFakeMock(\TIG\PostNL\Service\Timeframe\Options::class)->getMock();
$optionsExpected = $optionsMock->expects($this->any());
$optionsExpected->method('get');
$optionsExpected->willReturn(['Daytime']);

return $optionsMock;
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function deliveryDateFallbackMock()
{
$fallbackMock = $this->getFakeMock(DeliveryDateFallback::class)->getMock();
$getFalback = $fallbackMock->expects($this->any());
$getFalback->method('get');
$getFalback->willReturn('19-11-2016');

$getFalback2 = $fallbackMock->expects($this->any());
$getFalback2->method('getDate');
$getFalback2->willReturn('19-11-2016');
$getFallback = $fallbackMock->expects($this->any());
$getFallback->method('get');
$getFallback->willReturn('19-11-2016');

$getFallback2 = $fallbackMock->expects($this->any());
$getFallback2->method('getDate');
$getFallback2->willReturn('19-11-2016');

return $fallbackMock;
}
Expand Down
27 changes: 26 additions & 1 deletion Webservices/Endpoints/SentDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

use Magento\Customer\Model\Address\AbstractAddress as Address;
use TIG\PostNL\Api\Data\OrderInterface as PostNLOrder;
use TIG\PostNL\Service\Order\ProductInfo;
use TIG\PostNL\Service\Timeframe\Options;
use TIG\PostNL\Webservices\AbstractEndpoint;
use TIG\PostNL\Webservices\Api\Message;
Expand Down Expand Up @@ -158,12 +159,36 @@ public function setParameters($address, $storeId, PostNLOrder $postNLOrder)
'DeliveryDate' => $this->getDeliveryDate($address, $postNLOrder),
'ShippingDuration' => '1', // Request by PostNL not to use $postNLOrder->getShippingDuration()
'AllowSundaySorting' => $this->timeframeOptions->isSundaySortingAllowed(),
'Options' => $this->timeframeOptions->get($this->getCountryId())
'Options' => [$this->getOption($postNLOrder)]
],
'Message' => $this->message
];
}

/**
* GetSentDate 2.2 doesn't support multiple options for requests. That's why we send
* along the option actually selected.
*
* @param PostNLOrder $postNLOrder
*
* @return string
*/
private function getOption(PostNLOrder $postNLOrder)
{
$availableOptions = $this->timeframeOptions->get($this->getCountryId());
$currentType = $postNLOrder->getType();

if (in_array($currentType, $availableOptions)) {
return $currentType;
}

if ($currentType == ProductInfo::SHIPMENT_TYPE_PG) {
return ucfirst(ProductInfo::TYPE_PICKUP);
}

return ProductInfo::SHIPMENT_TYPE_DAYTIME;
}

/**
* This endpoint is only available for dutch addresses.
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"require": {
"php": "~7.0|~7.1|~7.2",
"ext-soap": "*",
"magento/framework": ">=100.1.0,<=100.1.17|>=101.0.0,<=101.0.8|>=102.0.0,<=102.0.1",
"magento/framework": ">=100.1.0,<=100.1.18|>=101.0.0,<=101.0.9|>=102.0.0,<=102.0.2",
"setasign/fpdi-fpdf": "2.1",
"zendframework/zend-barcode" : "2.5.2|2.7"
},
Expand Down
3 changes: 2 additions & 1 deletion etc/adminhtml/system/postnlsettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@
<include path="TIG_PostNL::system/postnlsettings/idcheck.xml"/>
<include path="TIG_PostNL::system/postnlsettings/cargo.xml"/>
<include path="TIG_PostNL::system/postnlsettings/eps.xml"/>
<include path="TIG_PostNL::system/postnlsettings/peps.xml"/>
<!-- Temporarily hide priority settings, because UX adjustments need to be implemented first -->
<!-- <include path="TIG_PostNL::system/postnlsettings/peps.xml"/> -->
<include path="TIG_PostNL::system/postnlsettings/extraathome.xml"/>
<include path="TIG_PostNL::system/postnlsettings/trackandtrace.xml"/>

Expand Down

0 comments on commit 23eff8a

Please sign in to comment.