/**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         /** @var  \Magento\Customer\Api\Data\CustomerInterface $customer */
         $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         if ($defaultShipping = $customer->getDefaultShipping()) {
             /** @var  \Magento\Customer\Model\Data\Address $address */
             $address = $this->addressRepository->getById($defaultShipping);
             if ($address) {
                 $this->_customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
             }
         }
         if ($defaultBilling = $customer->getDefaultBilling()) {
             $address = $this->addressRepository->getById($defaultBilling);
             if ($address) {
                 $this->_customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegionId() : null, 'postcode' => $address->getPostcode()]);
             }
         }
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
Example #2
0
 /**
  * Reset quote reward point amount
  *
  * @param \Magento\Customer\CustomerData\Customer $subject
  * @param \Closure $proceed
  *
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundGetSectionData(\Magento\Customer\CustomerData\Customer $subject, \Closure $proceed)
 {
     /** unset customer first name  */
     if (!$this->customerSession->isLoggedIn() && $this->persistentData->isEnabled() && $this->persistentSession->isPersistent()) {
         return [];
     }
     return $proceed();
 }
 /**
  * Set quote to be loaded even if not active
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && !$this->_persistentData->isShoppingCartPersist())) {
         return;
     }
     if ($this->_checkoutSession) {
         $this->_checkoutSession->setLoadInactive();
     }
 }
 /**
  * @param \Magento\Checkout\Model\DefaultConfigProvider $subject
  * @param array $result
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result)
 {
     if ($this->persistentHelper->isEnabled() && $this->persistentSession->isPersistent() && !$this->customerSession->isLoggedIn()) {
         /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
         $quoteIdMask = $this->quoteIdMaskFactory->create();
         $result['quoteData']['entity_id'] = $quoteIdMask->load($this->checkoutSession->getQuote()->getId(), 'quote_id')->getMaskedId();
     }
     return $result;
 }
 /**
  * Prevent clear checkout session
  *
  * @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()) {
             $action->setClearCheckoutSession(false);
         }
     }
 }
 /**
  * Apply persistent data
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute($observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentSession->isPersistent() || $this->_customerSession->isLoggedIn()) {
         return $this;
     }
     /** @var \Magento\Persistent\Model\Persistent\Config $persistentConfig */
     $persistentConfig = $this->_persistentConfigFactory->create();
     $persistentConfig->setConfigFilePath($this->_persistentData->getPersistentConfigFilePath())->fire();
     return $this;
 }
 /**
  * Make persistent quote to be guest
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($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();
 }
 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         $customer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
 /**
  * Renew persistent cookie
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isEnabled() || !$this->_persistentSession->isPersistent()) {
         return;
     }
     /** @var $request \Magento\Framework\App\RequestInterface */
     $request = $observer->getEvent()->getRequest();
     if ($this->_customerSession->isLoggedIn() || $request->getFullActionName() == 'customer_account_logout') {
         $this->_sessionFactory->create()->renewPersistentCookie($this->_persistentData->getLifeTime(), $this->_customerSession->getCookiePath());
     }
 }
Example #12
0
 /**
  * Set persistent data to customer session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute($observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isShoppingCartPersist()) {
         return $this;
     }
     if ($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn()) {
         $customer = $this->_customerAccountService->getCustomer($this->_persistentSession->getSession()->getCustomerId());
         $this->_customerSession->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());
     }
     return $this;
 }
 /**
  * Update customer id and customer group id if user is in persistent session
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentSession->isPersistent()) {
         return;
     }
     $customerCookies = $observer->getEvent()->getCustomerCookies();
     if ($customerCookies instanceof \Magento\Framework\DataObject) {
         $persistentCustomer = $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId());
         $customerCookies->setCustomerId($persistentCustomer->getId());
         $customerCookies->setCustomerGroupId($persistentCustomer->getGroupId());
     }
 }
 /**
  * Synchronize persistent session info
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if (!$this->_persistentData->isEnabled() || !$this->_persistentSession->isPersistent()) {
         return;
     }
     /** @var $sessionModel \Magento\Persistent\Model\Session */
     $sessionModel = $this->_persistentSession->getSession();
     /** @var $request \Magento\Framework\App\RequestInterface */
     $request = $observer->getEvent()->getRequest();
     // Quote Id could be changed only by logged in customer
     if ($this->_customerSession->isLoggedIn() || $request && $request->getActionName() == 'logout' && $request->getControllerName() == 'account') {
         $sessionModel->save();
     }
 }
 /**
  * Prevent express checkout
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn())) {
         return;
     }
     /** @var $controllerAction \Magento\Checkout\Controller\Express\RedirectLoginInterface*/
     $controllerAction = $observer->getEvent()->getControllerAction();
     if (!$controllerAction || !$controllerAction instanceof \Magento\Checkout\Controller\Express\RedirectLoginInterface || $controllerAction->getRedirectActionName() != $controllerAction->getRequest()->getActionName()) {
         return;
     }
     $this->messageManager->addNotice(__('To check out, please sign in using your email address.'));
     $customerBeforeAuthUrl = $this->_url->getUrl('persistent/index/expressCheckout');
     $this->_expressRedirectHelper->redirectLogin($controllerAction, $customerBeforeAuthUrl);
 }
 /**
  * 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);
     }
 }
Example #17
0
 /**
  * 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();
         }
     }
 }
 /**
  * Apply persistent data to specific block
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_persistentSession->isPersistent() || $this->_customerSession->isLoggedIn()) {
         return $this;
     }
     /** @var $block \Magento\Framework\View\Element\AbstractBlock */
     $block = $observer->getEvent()->getBlock();
     if (!$block) {
         return $this;
     }
     $configFilePath = $observer->getEvent()->getConfigFilePath();
     if (!$configFilePath) {
         $configFilePath = $this->_persistentData->getPersistentConfigFilePath();
     }
     /** @var $persistentConfig \Magento\Persistent\Model\Persistent\Config */
     $persistentConfig = $this->_persistentConfigFactory->create();
     $persistentConfig->setConfigFilePath($configFilePath);
     foreach ($persistentConfig->getBlockConfigInfo(get_class($block)) as $persistentConfigInfo) {
         $persistentConfig->fireOne($persistentConfigInfo, $block);
     }
     return $this;
 }
 /**
  * Disable guest checkout if we are in persistent mode
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_persistentSession->isPersistent()) {
         $observer->getEvent()->getResult()->setIsAllowed(false);
     }
 }
 /**
  * Disable guest checkout if we are in persistent mode
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute($observer)
 {
     if ($this->_persistentSession->isPersistent()) {
         $observer->getEvent()->getResult()->setIsAllowed(false);
     }
 }
Example #21
0
 /**
  * Check whether persistent mode is running
  *
  * @return bool
  */
 protected function _isPersistent()
 {
     return $this->_persistentSession->isPersistent();
 }