/**
  * 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);
         }
     }
 }
 /**
  * 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();
 }
Esempio n. 4
0
 /**
  * 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');
 }
 public function testSetGuest()
 {
     $this->checkoutSessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('getId')->will($this->returnValue(11));
     $this->persistentDataMock->expects($this->never())->method('isShoppingCartPersist');
     $this->quoteMock->expects($this->once())->method('getPaymentsCollection')->will($this->returnValue($this->abstractCollectionMock));
     $this->quoteMock->expects($this->once())->method('getAddressesCollection')->will($this->returnValue($this->abstractCollectionMock));
     $this->abstractCollectionMock->expects($this->exactly(2))->method('walk')->with('delete');
     $this->quoteMock->expects($this->once())->method('setIsActive')->with(true)->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('setCustomerEmail')->with(null)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('setCustomerFirstname')->with(null)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('setCustomerLastname')->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->quoteMock->expects($this->once())->method('setIsPersistent')->with(false)->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('removeAllAddresses')->will($this->returnValue($this->quoteMock));
     $quoteAddressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', [], [], '', false);
     $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($quoteAddressMock));
     $this->quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($quoteAddressMock));
     $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
     $this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
     $this->persistentSessionMock->expects($this->once())->method('getSession')->will($this->returnValue($this->sessionMock));
     $this->sessionMock->expects($this->once())->method('removePersistentCookie')->will($this->returnValue($this->sessionMock));
     $this->model->setGuest(false);
 }