From 498681cfe6a736f5cb6befd296cde6365d4d4475 Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Wed, 18 May 2022 20:34:22 -0400 Subject: [PATCH] Fix redirecting to cart for some multi-store sites --- Helper/Data.php | 25 +++++++++++++++++++ Model/Config/Backend/ModifyTimestamp.php | 18 ++++++------- .../Model/Session/SuccessValidatorPlugin.php | 9 +++---- composer.json | 2 +- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 3dc4ae2..7ed29c1 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -9,12 +9,29 @@ use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; +use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Store\Model\ScopeInterface; use MagePal\PreviewCheckoutSuccessPage\Model\Config\Backend\ValidFor; class Data extends AbstractHelper { const XML_PATH_ACTIVE = 'magepal_checkout/preview_success_page/active'; + /** + * @var DateTime + */ + private $dateTime; + + /** + * @param Context $context + * @param DateTime $dateTime + */ + public function __construct( + Context $context, + DateTime $dateTime + ) { + parent::__construct($context); + $this->dateTime = $dateTime; + } /** * Whether is active @@ -83,4 +100,12 @@ public function getModifyTimestamp() ScopeInterface::SCOPE_STORE ); } + + /** + * @return false|int + */ + public function getTimeStamp() + { + return strtotime($this->dateTime->gmtDate()); + } } diff --git a/Model/Config/Backend/ModifyTimestamp.php b/Model/Config/Backend/ModifyTimestamp.php index f4b69bb..43d2f28 100644 --- a/Model/Config/Backend/ModifyTimestamp.php +++ b/Model/Config/Backend/ModifyTimestamp.php @@ -14,14 +14,14 @@ use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\Registry; use Magento\Framework\Stdlib\DateTime\TimezoneInterface; +use MagePal\PreviewCheckoutSuccessPage\Helper\Data; class ModifyTimestamp extends Value { - /** - * @var TimezoneInterface + * @var Data */ - private $localeDate; + private $dataHelper; /** * Serialized constructor @@ -32,20 +32,20 @@ class ModifyTimestamp extends Value * @param TypeListInterface $cacheTypeList * @param AbstractResource|null $resource * @param AbstractDb|null $resourceCollection + * @param Data $dataHelper * @param array $data - * @param TimezoneInterface $localeDate */ public function __construct( Context $context, Registry $registry, ScopeConfigInterface $config, TypeListInterface $cacheTypeList, - TimezoneInterface $localeDate, AbstractResource $resource = null, AbstractDb $resourceCollection = null, + Data $dataHelper, array $data = [] ) { - $this->localeDate = $localeDate; + $this->dataHelper = $dataHelper; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } @@ -54,9 +54,7 @@ public function __construct( */ public function beforeSave() { - $this->setValue($this->localeDate->scopeTimeStamp(ScopeConfigInterface::SCOPE_TYPE_DEFAULT)); - - parent::beforeSave(); - return $this; + $this->setValue($this->dataHelper->getTimeStamp()); + return parent::beforeSave(); } } diff --git a/Plugin/Model/Session/SuccessValidatorPlugin.php b/Plugin/Model/Session/SuccessValidatorPlugin.php index 0b24087..8f69f73 100644 --- a/Plugin/Model/Session/SuccessValidatorPlugin.php +++ b/Plugin/Model/Session/SuccessValidatorPlugin.php @@ -44,20 +44,17 @@ class SuccessValidatorPlugin * @param RequestInterface $request * @param Session $checkoutSession * @param CollectionFactory $orderCollectionFactory - * @param TimezoneInterface $localeDate */ public function __construct( Data $dataHelper, RequestInterface $request, Session $checkoutSession, - CollectionFactory $orderCollectionFactory, - TimezoneInterface $localeDate + CollectionFactory $orderCollectionFactory ) { $this->dataHelper = $dataHelper; $this->request = $request; $this->checkoutSession = $checkoutSession; $this->orderCollectionFactory = $orderCollectionFactory; - $this->localeDate = $localeDate; } /** @@ -106,11 +103,11 @@ public function getOrderByIncrementId($increment_id) protected function isValidAccessCode() { $accessCode = $this->request->getParam('previewAccessCode', null); + $validUntil = $this->dataHelper->getModifyTimestamp() + 60 * $this->dataHelper->getValidFor(); if ($accessCode && $accessCode === $this->dataHelper->getAccessCode() - && ($this->dataHelper->getModifyTimestamp() + 60 * $this->dataHelper->getValidFor()) - > $this->localeDate->scopeTimeStamp(ScopeConfigInterface::SCOPE_TYPE_DEFAULT) + && $validUntil > $this->dataHelper->getTimeStamp() ) { return true; } diff --git a/composer.json b/composer.json index 3a84719..d19221c 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "magepal/magento2-checkout-success-misc-script":"Add miscellaneous HTML and scripts to your checkout success page" }, "type": "magento2-module", - "version": "1.0.12", + "version": "1.1.0", "autoload": { "files": [ "registration.php"