Esempio n. 1
0
 /**
  * Make quote to be guest
  *
  * @param bool $checkQuote Check quote to be persistent (not stolen)
  * @return void
  */
 public function setGuest($checkQuote = false)
 {
     /** @var $quote \Magento\Sales\Model\Quote */
     $quote = $this->checkoutSession->getQuote();
     if ($quote && $quote->getId()) {
         if ($checkQuote && !$this->persistentData->isShoppingCartPersist() && !$quote->getIsPersistent()) {
             $this->checkoutSession->clearQuote()->clearStorage();
             return;
         }
         $quote->getPaymentsCollection()->walk('delete');
         $quote->getAddressesCollection()->walk('delete');
         $this->_setQuotePersistent = false;
         $quote->setIsActive(true)->setCustomerId(null)->setCustomerEmail(null)->setCustomerFirstname(null)->setCustomerLastname(null)->setCustomerGroupId(\Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID)->setIsPersistent(false)->removeAllAddresses();
         //Create guest addresses
         $quote->getShippingAddress();
         $quote->getBillingAddress();
         $quote->collectTotals()->save();
     }
     $this->persistentSession->getSession()->removePersistentCookie();
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @codeCoverageIgnore
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $this->checkoutSession->clearQuote()->clearStorage();
 }