Skip to content

Commit

Permalink
Implement TimeZone Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyGotfridt committed Mar 26, 2022
1 parent 2ffe454 commit a64e034
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 39 deletions.
28 changes: 14 additions & 14 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Improntus\PedidosYa\Model\TokenFactory;
use Improntus\PedidosYa\Model\PedidosYaFactory;
use Improntus\PedidosYa\Helper\Logger\Logger as PedidosYaLogger;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;

/**
* Class Data
Expand Down Expand Up @@ -85,18 +86,11 @@ class Data extends AbstractHelper
protected $_pedidosYaLogger;

/**
* @param Context $context
* @param ScopeConfigInterface $scopeConfig
* @param TokenFactory $tokenFactory
* @param WaypointFactory $waypointFactory
* @param ShipmentNotifier $shipmentNotifier
* @param TrackFactory $trackFactory
* @param Order $convertOrder
* @param StatusFactory $trackStatusFactory
* @param ResultFactory $trackResultFactory
* @param PedidosYaFactory $pedidosYaFactory
* @param PedidosYaLogger $pedidosYaLogger
* @var TimezoneInterface
*/
protected $timezone;


public function __construct(
Context $context,
ScopeConfigInterface $scopeConfig,
Expand All @@ -108,7 +102,8 @@ public function __construct(
StatusFactory $trackStatusFactory,
ResultFactory $trackResultFactory,
PedidosYaFactory $pedidosYaFactory,
PedidosYaLogger $pedidosYaLogger
PedidosYaLogger $pedidosYaLogger,
TimezoneInterface $timezone
) {
$this->_scopeConfig = $scopeConfig;
$this->_tokenFactory = $tokenFactory;
Expand All @@ -120,6 +115,7 @@ public function __construct(
$this->_trackStatusFactory = $trackStatusFactory;
$this->_trackResultFactory = $trackResultFactory;
$this->_pedidosYaLogger = $pedidosYaLogger;
$this->timezone = $timezone;
parent::__construct($context);
}

Expand Down Expand Up @@ -468,9 +464,13 @@ public function getTrackingUrl($tracking)
*/
public function checkWaypointAvailability($waypointId, $deliveryTime)
{
$days = [1 => 'monday', 2 => 'tuesday', 3 => 'wednesday', 4 => 'thursday', 5 => 'friday', 6 => 'saturday', 7 => 'sunday'];
/**
* Fix Format W: Numerical representation of the day of the week 0 (Sunday) > 6 (Saturday)
* Implement Timezone Interface to get day
*/
$days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday'];
$waypoint = $this->getWaypointById($waypointId);
$day = $days[date('w', strtotime($deliveryTime))];
$day = $days[date("w", strtotime($this->timezone->date()->format("Y-m-d\TH:i:s\Z")))];
$openHour = $waypoint->getData('working_hours_'. $day. '_open');
$closeHour = $waypoint->getData('working_hours_'. $day. '_close');

Expand Down
32 changes: 8 additions & 24 deletions Model/Carrier/PedidosYa.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Improntus\PedidosYa\Model\Webservice;
use Magento\Framework\Xml\Security;
use Magento\Checkout\Model\Session;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;

/**
* Class PedidosYa
Expand Down Expand Up @@ -93,29 +94,11 @@ class PedidosYa extends AbstractCarrierOnline implements CarrierInterface
protected $_date;

/**
* @param ScopeConfigInterface $scopeConfig
* @param ErrorFactory $rateErrorFactory
* @param LoggerInterface $logger
* @param Security $xmlSecurity
* @param ElementFactory $xmlElFactory
* @param ResultFactory $rateFactory
* @param MethodFactory $rateMethodFactory
* @param \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory
* @param \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory
* @param StatusFactory $trackStatusFactory
* @param RegionFactory $regionFactory
* @param CountryFactory $countryFactory
* @param CurrencyFactory $currencyFactory
* @param Data $directoryData
* @param StockRegistryInterface $stockRegistry
* @param RequestInterface $request
* @param Webservice $webservice
* @param PedidosYaHelper $pedidosYaHelper
* @param Session $checkoutSession
* @param CartRepositoryInterface $quoteRepository
* @param DateTime $date
* @param array $data
* @var TimezoneInterface
*/
protected $timezone;


public function __construct(
ScopeConfigInterface $scopeConfig,
ErrorFactory $rateErrorFactory,
Expand All @@ -138,6 +121,7 @@ public function __construct(
Session $checkoutSession,
CartRepositoryInterface $quoteRepository,
DateTime $date,
TimezoneInterface $timezone,
array $data = []
)
{
Expand All @@ -149,7 +133,7 @@ public function __construct(
$this->_checkoutSession = $checkoutSession;
$this->_quoteRepository = $quoteRepository;
$this->_date = $date;

$this->timezone = $timezone;
parent::__construct(
$scopeConfig,
$rateErrorFactory,
Expand Down Expand Up @@ -372,7 +356,7 @@ public function collectRates(RateRequest $request)
[
"referenceId" => $referenceId,
"isTest" => $this->_helper->getMode() == 'testing',
"deliveryTime" => $this->_date->gmtDate('Y-m-d\TH:i:s\Z'),
"deliveryTime" => $this->timezone->date()->format('Y-m-d\TH:i:s\Z'),
"volume" => $totalVolume,
"weight" => $totalWeight,
"items" => $itemsWspedidosYa,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "improntus/module-pedidosya-magento-2",
"description": "Pedidos Ya module",
"type": "magento2-module",
"version": "1.0.21",
"version": "1.0.22",
"require": {
},
"autoload": {
Expand Down

0 comments on commit a64e034

Please sign in to comment.