/**
  * 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();
 }
 /**
  * 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);
     }
 }
 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();
 }