Skip to content

Commit

Permalink
merge develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tig-rikjonkmans committed Jun 20, 2018
2 parents d1ea49a + dc73601 commit 2fccbb5
Show file tree
Hide file tree
Showing 70 changed files with 2,031 additions and 322 deletions.
12 changes: 12 additions & 0 deletions Api/Data/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,16 @@ public function setUpdatedAt($value);
* @return string
*/
public function getUpdatedAt();

/**
* @return int
*/
public function getShippingDuration();

/**
* @param $value
*
* @return int
*/
public function setShippingDuration($value);
}
2 changes: 1 addition & 1 deletion Config/CheckoutConfiguration/IsShippingOptionsActive.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function __construct(
*/
public function getValue()
{
if (!$this->shippingOptions->isShippingoptionsActive()) {
if (!$this->shippingOptions->isShippingoptionsActive() || $this->accountConfiguration->isModusOff()) {
return false;
}

Expand Down
9 changes: 4 additions & 5 deletions Config/Csv/Import/Matrixrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,19 @@ public function afterSave()
{
/** @var \Zend\Stdlib\Parameters $requestFiles */
$requestFiles = $this->request->getFiles();
$files = $requestFiles->offsetGet('groups');

$files = $requestFiles->offsetGet('groups');
if (!isset($files['tig_postnl']) || !isset($files['tig_postnl']['fields']['matrixrate_import'])) {
return parent::beforeSave();
}

$fileName = $files['tig_postnl']['fields']['matrixrate_import']['value']['tmp_name'];

$websiteId = $this->request->getParam('website', 0);
$fileName = $files['tig_postnl']['fields']['matrixrate_import']['value']['tmp_name'];
if (empty($fileName)) {
return parent::afterSave();
}

$file = $this->getCsvFile($fileName);
$this->matrixrateData->import($file);
$this->matrixrateData->import($file, $websiteId);
$file->close();

return parent::afterSave();
Expand Down
75 changes: 75 additions & 0 deletions Config/Provider/ShippingDuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
*
* ..::..
* ..::::::::::::..
* ::'''''':''::'''''::
* ::.. ..: : ....::
* :::: ::: : : ::
* :::: ::: : ''' ::
* ::::..:::..::.....::
* ''::::::::::::''
* ''::''
*
*
* NOTICE OF LICENSE
*
* This source file is subject to the Creative Commons License.
* It is available through the world-wide-web at this URL:
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
* If you are unable to obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact [email protected] for more information.
*
* @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\Config\Provider;

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;

class ShippingDuration extends AbstractSource
{
const CONFIGURATION_VALUE = 'default';
/**
* @return array
*/
public function getAllOptions()
{
$options[] = [
'value' => static::CONFIGURATION_VALUE,
// @codingStandardsIgnoreLine
'label' => __('Use configuration value')
];

foreach (range(0, 14) as $day) {
$options[] = [
'value' => $day,
'label' => $this->getLabel($day)
];
}

return $options;
}

/**
* @param $day
*
* @return \Magento\Framework\Phrase
*/
private function getLabel($day)
{
if ($day == 1) {
// @codingStandardsIgnoreLine
return __('%1 Day', $day);
}

// @codingStandardsIgnoreLine
return __('%1 Days', $day);
}
}
59 changes: 56 additions & 3 deletions Config/Provider/Webshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@
*/
namespace TIG\PostNL\Config\Provider;

/**
* This class contains all configuration options related to webshop options.
* This will cause that it is too long for Code Sniffer to check.
*
* @codingStandardsIgnoreStart
*/
class Webshop extends AbstractConfigProvider
{
const XPATH_WEBSHOP_LABEL_SIZE = 'tig_postnl/webshop_printer/label_size';
const XPATH_WEBSHOP_CUTOFFTIME = 'tig_postnl/webshop_shipping/cutoff_time';
const XPATH_WEBSHOP_SHIPMENTDAYS = 'tig_postnl/webshop_shipping/shipment_days';

const XPATH_WEBSHOP_LABEL_SIZE = 'tig_postnl/webshop_printer/label_size';
const XPATH_WEBSHOP_CUTOFFTIME = 'tig_postnl/webshop_shipping/cutoff_time';
const XPATH_WEBSHOP_SATURDAY_CUTOFFTIME = 'tig_postnl/webshop_shipping/saturday_cutoff_time';
const XPATH_WEBSHOP_SUNDAY_CUTOFFTIME = 'tig_postnl/webshop_shipping/sunday_cutoff_time';
const XPATH_WEBSHOP_SHIPMENTDAYS = 'tig_postnl/webshop_shipping/shipment_days';
const XPATH_WEBSHOP_SHIPPING_DURATION = 'tig_postnl/webshop_shipping/shipping_duration';

const XPATH_TRACK_AND_TRACE_ENABLED = 'tig_postnl/webshop_track_and_trace/email_enabled';
const XPATH_TRACK_AND_TRACE_BCC_EMAIL = 'tig_postnl/webshop_track_and_trace/email_bcc';
Expand All @@ -52,6 +62,15 @@ public function getLabelSize()
return $this->getConfigFromXpath(self::XPATH_WEBSHOP_LABEL_SIZE);
}

/**
* @param $storeId
* @return mixed
*/
public function getShippingDuration($storeId = null)
{
return $this->getConfigFromXpath(self::XPATH_WEBSHOP_SHIPPING_DURATION, $storeId);
}

/**
* @return mixed
*/
Expand All @@ -60,6 +79,40 @@ public function getCutOffTime()
return $this->getConfigFromXpath(self::XPATH_WEBSHOP_CUTOFFTIME);
}

/**
* @return mixed
*/
public function getSaturdayCutOffTime()
{
return $this->getConfigFromXpath(self::XPATH_WEBSHOP_SATURDAY_CUTOFFTIME);
}

/**
* @return mixed
*/
public function getSundayCutOffTime()
{
return $this->getConfigFromXpath(self::XPATH_WEBSHOP_SUNDAY_CUTOFFTIME);
}

/**
* @param $day
*
* @return mixed
*/
public function getCutOffTimeForDay($day)
{
switch ($day) {
case '7':
case '0':
return $this->getSundayCutOffTime();
case '6':
return $this->getSaturdayCutOffTime();
default :
return $this->getCutOffTime();
}
}

/**
* @return mixed
*/
Expand Down
13 changes: 3 additions & 10 deletions Config/Source/Settings/CutOffSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class CutOffSettings implements ArrayInterface
*/
public function toOptionArray()
{
$options = [
// @codingStandardsIgnoreLine
['value' => '', 'label' => __('No cut-off time')],
];
$options = [];

for ($hour = 0; $hour < 24; $hour++) {
$options = array_merge($options, $this->addHour($hour));
Expand All @@ -59,15 +56,11 @@ public function toOptionArray()
*/
private function addHour($hour)
{
$hour = str_pad($hour, 2, '0', STR_PAD_LEFT);

$hour = str_pad($hour, 2, '0', STR_PAD_LEFT);
$options = [];
if ($hour !== '00') {
// @codingStandardsIgnoreLine
$options[] = ['value' => $hour . ':00:00', 'label' => __($hour . ':00')];
}

// @codingStandardsIgnoreStart
$options[] = ['value' => $hour . ':00:00', 'label' => __($hour . ':00')];
$options[] = ['value' => $hour . ':15:00', 'label' => __($hour . ':15')];
$options[] = ['value' => $hour . ':30:00', 'label' => __($hour . ':30')];
$options[] = ['value' => $hour . ':45:00', 'label' => __($hour . ':45')];
Expand Down
67 changes: 67 additions & 0 deletions Config/Source/Settings/ShippingDuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
*
* ..::..
* ..::::::::::::..
* ::'''''':''::'''''::
* ::.. ..: : ....::
* :::: ::: : : ::
* :::: ::: : ''' ::
* ::::..:::..::.....::
* ''::::::::::::''
* ''::''
*
*
* NOTICE OF LICENSE
*
* This source file is subject to the Creative Commons License.
* It is available through the world-wide-web at this URL:
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
* If you are unable to obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact [email protected] for more information.
*
* @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\Config\Source\Settings;

use \Magento\Framework\Option\ArrayInterface;
use TIG\PostNL\Config\Provider\ShippingDuration as SourceProvider;

class ShippingDuration implements ArrayInterface
{
/**
* @var SourceProvider
*/
private $sourceProvider;

/**
* ShippingDuration constructor.
*
* @param SourceProvider $shippingDuration
*/
public function __construct(
SourceProvider $shippingDuration
) {
$this->sourceProvider = $shippingDuration;
}

/**
* @return array
*/
public function toOptionArray()
{
$options = $this->sourceProvider->getAllOptions();
$options = array_filter($options, function ($option) {
return $option['value'] !== SourceProvider::CONFIGURATION_VALUE;
});

return $options;
}
}
15 changes: 13 additions & 2 deletions Controller/AbstractDeliveryOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use TIG\PostNL\Service\Carrier\QuoteToRateRequest;
use TIG\PostNL\Webservices\Endpoints\DeliveryDate;
use Magento\Quote\Model\Quote\Address\RateRequest;
use TIG\PostNL\Service\Quote\ShippingDuration;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\Action;
use Magento\Checkout\Model\Session;
Expand All @@ -59,6 +60,12 @@ abstract class AbstractDeliveryOptions extends Action
//@codingStandardsIgnoreLine
protected $deliveryEndpoint;

/**
* @var ShippingDuration
*/
//@codingStandardsIgnoreLine
protected $shippingDuration;

/**
* @var QuoteToRateRequest
*/
Expand All @@ -82,18 +89,21 @@ abstract class AbstractDeliveryOptions extends Action
* @param Session $checkoutSession
* @param QuoteToRateRequest $quoteToRateRequest
* @param DeliveryDate $deliveryDate
* @param ShippingDuration $shippingDuration
*/
public function __construct(
Context $context,
OrderFactory $orderFactory,
Session $checkoutSession,
QuoteToRateRequest $quoteToRateRequest,
ShippingDuration $shippingDuration,
DeliveryDate $deliveryDate = null
) {
$this->orderFactory = $orderFactory;
$this->checkoutSession = $checkoutSession;
$this->deliveryEndpoint = $deliveryDate;
$this->quoteToRateRequest = $quoteToRateRequest;
$this->shippingDuration = $shippingDuration;

parent::__construct($context);
}
Expand Down Expand Up @@ -154,10 +164,11 @@ protected function getDeliveryDay($address)
return $this->checkoutSession->getPostNLDeliveryDate();
}

$quote = $this->checkoutSession->getQuote();
$quote = $this->checkoutSession->getQuote();
$storeId = $quote->getStoreId();
$shippingDuration = $this->shippingDuration->get();
$this->deliveryEndpoint->setStoreId($storeId);
$this->deliveryEndpoint->setParameters($address);
$this->deliveryEndpoint->setParameters($address, $shippingDuration);
$response = $this->deliveryEndpoint->call();

if (!is_object($response) || !isset($response->DeliveryDate)) {
Expand Down
6 changes: 5 additions & 1 deletion Controller/DeliveryOptions/Locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use Magento\Framework\App\Action\Context;
use Magento\Checkout\Model\Session;
use Magento\Framework\Exception\LocalizedException;
use TIG\PostNL\Service\Quote\ShippingDuration;

class Locations extends AbstractDeliveryOptions
{
Expand Down Expand Up @@ -70,6 +71,7 @@ class Locations extends AbstractDeliveryOptions
* @param LocationsEndpoint $locations
* @param DeliveryDate $deliveryDate
* @param Calculator $priceCalculator
* @param ShippingDuration $shippingDuration
*/
public function __construct(
Context $context,
Expand All @@ -79,7 +81,8 @@ public function __construct(
AddressEnhancer $addressEnhancer,
LocationsEndpoint $locations,
DeliveryDate $deliveryDate,
Calculator $priceCalculator
Calculator $priceCalculator,
ShippingDuration $shippingDuration
) {
$this->addressEnhancer = $addressEnhancer;
$this->locationsEndpoint = $locations;
Expand All @@ -90,6 +93,7 @@ public function __construct(
$orderFactory,
$checkoutSession,
$quoteToRateRequest,
$shippingDuration,
$deliveryDate
);
}
Expand Down
Loading

0 comments on commit 2fccbb5

Please sign in to comment.