Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RemovePersistentCookieOnRegisterObserver.php
Go to the documentation of this file.
1 <?php
8 
10 
15 {
21  protected $_customerSession;
22 
28  protected $_persistentSession = null;
29 
35  protected $_persistentData = null;
36 
40  protected $quoteManager;
41 
48  public function __construct(
49  \Magento\Persistent\Helper\Session $persistentSession,
50  \Magento\Persistent\Helper\Data $persistentData,
51  \Magento\Customer\Model\Session $customerSession,
52  \Magento\Persistent\Model\QuoteManager $quoteManager
53  ) {
54  $this->quoteManager = $quoteManager;
55  $this->_persistentSession = $persistentSession;
56  $this->_persistentData = $persistentData;
57  $this->_customerSession = $customerSession;
58  }
59 
66  public function execute(\Magento\Framework\Event\Observer $observer)
67  {
68  if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent()) {
69  return;
70  }
71 
72  $this->_persistentSession->getSession()->removePersistentCookie();
73 
74  if (!$this->_customerSession->isLoggedIn()) {
75  $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null);
76  }
77 
78  $this->quoteManager->setGuest();
79  }
80 }
$persistentSession
Definition: persistent.php:11