/** * Reset session data when customer re-authenticates * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute($observer) { $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null); if ($this->_requestHttp->getParam('context') != 'checkout') { $this->quoteManager->expire(); return; } $this->quoteManager->setGuest(); }
/** * Make persistent quote to be guest * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { /** @var $action \Magento\Persistent\Controller\Index */ $action = $observer->getEvent()->getControllerAction(); if ($action instanceof \Magento\Persistent\Controller\Index) { if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() || $this->_persistentData->isShoppingCartPersist()) { $this->quoteManager->setGuest(true); } } }
/** * Check and clear session data if persistent session expired * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if (!$this->_persistentData->canProcess($observer)) { return; } if ($this->_persistentData->isEnabled() && !$this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && $this->_checkoutSession->getQuoteId() && !$observer->getControllerAction() instanceof \Magento\Checkout\Controller\Onepage) { $this->_eventManager->dispatch('persistent_session_expired'); $this->quoteManager->expire(); $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null); } }
/** * Unset persistent cookie and make customer's quote as a guest * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute($observer) { if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent()) { return; } $this->_persistentSession->getSession()->removePersistentCookie(); if (!$this->_customerSession->isLoggedIn()) { $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null); } $this->quoteManager->setGuest(); }
/** * Save onepage checkout method to be register * * @return void */ public function execute() { if ($this->_getHelper()->isPersistent()) { $this->_getHelper()->getSession()->removePersistentCookie(); if (!$this->_customerSession->isLoggedIn()) { $this->_customerSession->setCustomerId(null)->setCustomerGroupId(null); } $this->quoteManager->setGuest(); } $checkoutUrl = $this->_redirect->getRefererUrl(); $this->getResponse()->setRedirect($checkoutUrl . (strpos($checkoutUrl, '?') ? '&' : '?') . 'register'); }
/** * Set persistent data into quote * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute($observer) { if (!$this->_persistentSession->isPersistent()) { return; } /** @var $quote \Magento\Quote\Model\Quote */ $quote = $observer->getEvent()->getQuote(); if (!$quote) { return; } if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && !$this->_persistentData->isShoppingCartPersist() && $this->quoteManager->isPersistent()) { //Quote is not actual customer's quote, just persistent $quote->setIsActive(false)->setIsPersistent(true); } }
public function testExpire() { $this->checkoutSessionMock->expects($this->once())->method('setLoadInactive')->will($this->returnValue($this->sessionMock)); $this->sessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('getIsActive')->will($this->returnValue(0)); $this->checkoutSessionMock->expects($this->never())->method('setCustomerData'); $this->quoteMock->expects($this->once())->method('setIsActive')->with(true)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('setIsPersistent')->with(false)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('setCustomerId')->with(null)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('setCustomerGroupId')->with(\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID)->will($this->returnValue($this->quoteMock)); $this->model->expire(); }