Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SynchronizePersistentInfoObserver.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
22 
28  protected $_persistentData = null;
29 
35  protected $_customerSession;
36 
42  public function __construct(
43  \Magento\Persistent\Helper\Data $persistentData,
44  \Magento\Persistent\Helper\Session $persistentSession,
45  \Magento\Customer\Model\Session $customerSession
46  ) {
47  $this->_persistentData = $persistentData;
48  $this->_persistentSession = $persistentSession;
49  $this->_customerSession = $customerSession;
50  }
51 
59  public function execute(Observer $observer)
60  {
61  if (!$this->_persistentData->isEnabled() || !$this->_persistentSession->isPersistent()) {
62  return;
63  }
64 
66  $sessionModel = $this->_persistentSession->getSession();
67 
69  $request = $observer->getEvent()->getRequest();
70 
71  // Quote Id could be changed only by logged in customer
72  if ($this->_customerSession->isLoggedIn() ||
73  $request && $request->getFullActionName() == 'customer_account_logout'
74  ) {
75  $sessionModel->save();
76  }
77  }
78 }
$persistentSession
Definition: persistent.php:11
__construct(\Magento\Persistent\Helper\Data $persistentData, \Magento\Persistent\Helper\Session $persistentSession, \Magento\Customer\Model\Session $customerSession)