Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EmulateQuoteObserver.php
Go to the documentation of this file.
1 <?php
8 
10 
15 {
22 
28  protected $_customerSession;
29 
35  protected $_checkoutSession;
36 
42  protected $_persistentSession = null;
43 
49  protected $_persistentData = null;
50 
58  public function __construct(
59  \Magento\Persistent\Helper\Session $persistentSession,
60  \Magento\Persistent\Helper\Data $persistentData,
61  \Magento\Checkout\Model\Session $checkoutSession,
62  \Magento\Customer\Model\Session $customerSession,
63  \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
64  ) {
65  $this->_persistentSession = $persistentSession;
66  $this->_persistentData = $persistentData;
67  $this->_checkoutSession = $checkoutSession;
68  $this->_customerSession = $customerSession;
69  $this->customerRepository = $customerRepository;
70  }
71 
78  public function execute(\Magento\Framework\Event\Observer $observer)
79  {
80  $stopActions = ['persistent_index_saveMethod', 'customer_account_createpost'];
81 
82  if (!$this->_persistentData->canProcess($observer)
83  || !$this->_persistentSession->isPersistent()
84  || $this->_customerSession->isLoggedIn()
85  ) {
86  return;
87  }
88 
89  $actionName = $observer->getEvent()->getRequest()->getFullActionName();
90 
91  if (in_array($actionName, $stopActions)) {
92  return;
93  }
94 
95  if ($this->_persistentData->isShoppingCartPersist()) {
96  $this->_checkoutSession->setCustomerData(
97  $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())
98  );
99  if (!$this->_checkoutSession->hasQuote()) {
100  $this->_checkoutSession->getQuote();
101  }
102  }
103  }
104 }
__construct(\Magento\Persistent\Helper\Session $persistentSession, \Magento\Persistent\Helper\Data $persistentData, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository)
$persistentSession
Definition: persistent.php:11
execute(\Magento\Framework\Event\Observer $observer)