Skip to content

Commit

Permalink
Fix redirecting to cart for some multi-store sites
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed May 19, 2022
1 parent 2e11d85 commit 498681c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
25 changes: 25 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,4 +100,12 @@ public function getModifyTimestamp()
ScopeInterface::SCOPE_STORE
);
}

/**
* @return false|int
*/
public function getTimeStamp()
{
return strtotime($this->dateTime->gmtDate());
}
}
18 changes: 8 additions & 10 deletions Model/Config/Backend/ModifyTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -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();
}
}
9 changes: 3 additions & 6 deletions Plugin/Model/Session/SuccessValidatorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 498681c

Please sign in to comment.