mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 09:17:35 +00:00
90 lines
2.4 KiB
PHP
90 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
namespace Magento\Persistent\Observer;
|
|
|
|
use Magento\Framework\Event\ObserverInterface;
|
|
|
|
/**
|
|
* Observer for setting "is_persistent" value to quote
|
|
*
|
|
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
|
|
*/
|
|
class SetQuotePersistentDataObserver implements ObserverInterface
|
|
{
|
|
/**
|
|
* Customer session
|
|
*
|
|
* @var \Magento\Customer\Model\Session
|
|
*/
|
|
protected $_customerSession;
|
|
|
|
/**
|
|
* Persistent session
|
|
*
|
|
* @var \Magento\Persistent\Helper\Session
|
|
*/
|
|
protected $_persistentSession = null;
|
|
|
|
/**
|
|
* Persistent data
|
|
*
|
|
* @var \Magento\Persistent\Helper\Data
|
|
*/
|
|
protected $_persistentData = null;
|
|
|
|
/**
|
|
* @var \Magento\Persistent\Model\QuoteManager
|
|
*/
|
|
protected $quoteManager;
|
|
|
|
/**
|
|
* @param \Magento\Persistent\Helper\Session $persistentSession
|
|
* @param \Magento\Persistent\Helper\Data $persistentData
|
|
* @param \Magento\Persistent\Model\QuoteManager $quoteManager
|
|
* @param \Magento\Customer\Model\Session $customerSession
|
|
*/
|
|
public function __construct(
|
|
\Magento\Persistent\Helper\Session $persistentSession,
|
|
\Magento\Persistent\Helper\Data $persistentData,
|
|
\Magento\Persistent\Model\QuoteManager $quoteManager,
|
|
\Magento\Customer\Model\Session $customerSession
|
|
) {
|
|
$this->_persistentSession = $persistentSession;
|
|
$this->quoteManager = $quoteManager;
|
|
$this->_customerSession = $customerSession;
|
|
$this->_persistentData = $persistentData;
|
|
}
|
|
|
|
/**
|
|
* Set persistent data into quote
|
|
*
|
|
* @param \Magento\Framework\Event\Observer $observer
|
|
* @return void
|
|
*/
|
|
public function execute(\Magento\Framework\Event\Observer $observer)
|
|
{
|
|
if (!$this->_persistentSession->isPersistent()) {
|
|
return;
|
|
}
|
|
|
|
/** @var $quote \Magento\Quote\Model\Quote */
|
|
$quote = $observer->getEvent()->getQuote();
|
|
if (!$quote) {
|
|
return;
|
|
}
|
|
|
|
if ((
|
|
($this->_persistentSession->isPersistent())
|
|
&& $this->_persistentData->isShoppingCartPersist()
|
|
)
|
|
&& $this->quoteManager->isPersistent()
|
|
) {
|
|
//Quote is not actual customer's quote, just persistent
|
|
$quote->setIsPersistent(true);
|
|
}
|
|
}
|
|
}
|