Example #1
0
 /**
  * Test covers case when quote is not yet initialized and customer data is set to checkout session model.
  *
  * Expected result - quote object should be loaded and customer data should be set to it.
  *
  * @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
  */
 public function testGetQuoteNotInitializedCustomerSet()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = $objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $customer = $customerRepository->getById(1);
     $this->_checkoutSession->setCustomerData($customer);
     /** Execute SUT */
     $quote = $this->_checkoutSession->getQuote();
     $this->_validateCustomerDataInQuote($quote);
 }
Example #2
0
 /**
  * Test covers case when quote is not yet initialized and customer data is set to checkout session model.
  *
  * Expected result - quote object should be loaded and customer data should be set to it.
  *
  * @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
  */
 public function testGetQuoteNotInitializedCustomerSet()
 {
     /** Preconditions */
     $customerIdFromFixture = 1;
     /** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerService */
     $customerService = Bootstrap::getObjectManager()->get('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     $customer = $customerService->getCustomer($customerIdFromFixture);
     $this->_checkoutSession->setCustomerData($customer);
     /** Execute SUT */
     $quote = $this->_checkoutSession->getQuote();
     $this->_validateCustomerDataInQuote($quote);
 }
 /**
  * Emulate quote by persistent data
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     $stopActions = ['persistent_index_saveMethod', 'customer_account_createpost'];
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent() || $this->_customerSession->isLoggedIn()) {
         return;
     }
     $actionName = $observer->getEvent()->getRequest()->getFullActionName();
     if (in_array($actionName, $stopActions)) {
         return;
     }
     if ($this->_persistentData->isShoppingCartPersist()) {
         $this->_checkoutSession->setCustomerData($this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId()));
         if (!$this->_checkoutSession->hasQuote()) {
             $this->_checkoutSession->getQuote();
         }
     }
 }
 /**
  * Expire persistent quote
  *
  * @return void
  */
 public function expire()
 {
     $quote = $this->checkoutSession->setLoadInactive()->getQuote();
     if ($quote->getIsActive() && $quote->getCustomerId()) {
         $this->checkoutSession->setCustomerData(null)->clearQuote()->clearStorage();
     } else {
         $quote->setIsActive(true)->setIsPersistent(false)->setCustomerId(null)->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
     }
 }
Example #5
0
 /**
  * @return void
  */
 protected function _expirePersistentSession()
 {
     $quote = $this->_checkoutSession->setLoadInactive()->getQuote();
     if ($quote->getIsActive() && $quote->getCustomerId()) {
         $this->_checkoutSession->setCustomerData(null)->clearQuote()->clearStorage();
     } else {
         $quote->setIsActive(true)->setIsPersistent(false)->setCustomerId(null)->setCustomerGroupId(\Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID);
     }
 }