/**
  * Process address additional data
  *
  * @param AddressAdditionalDataProcessor $subject
  * @param AddressAdditionalData $additionalData
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeProcess(AddressAdditionalDataProcessor $subject, AddressAdditionalData $additionalData)
 {
     if (!$this->persistentHelper->isEnabled() || !$this->persistentHelper->isRememberMeEnabled()) {
         return;
     }
     $checkboxStatus = $additionalData->getExtensionAttributes()->getPersistentRememberMe();
     $isRememberMeChecked = empty($checkboxStatus) ? false : true;
     $this->persistentSession->setRememberMeChecked($isRememberMeChecked);
     $this->checkoutSession->setRememberMeChecked($isRememberMeChecked);
 }
 /**
  * Set Checked status of "Remember Me"
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isEnabled() || !$this->_persistentData->isRememberMeEnabled()) {
         return;
     }
     /** @var $controllerAction \Magento\Framework\App\RequestInterface */
     $request = $observer->getEvent()->getRequest();
     if ($request) {
         $rememberMeCheckbox = $request->getPost('persistent_remember_me');
         $this->_persistentSession->setRememberMeChecked((bool) $rememberMeCheckbox);
         if ($request->getFullActionName() == 'checkout_onepage_saveBilling' || $request->getFullActionName() == 'customer_account_createpost') {
             $this->_checkoutSession->setRememberMeChecked((bool) $rememberMeCheckbox);
         }
     }
 }
 /**
  * Set Checked status of "Remember Me"
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isEnabled() || !$this->_persistentData->isRememberMeEnabled()) {
         return;
     }
     /** @var $request \Magento\Framework\App\RequestInterface */
     $request = $observer->getEvent()->getRequest();
     if ($request && $request->isXmlHttpRequest()) {
         $requestData = [];
         $content = $request->getContent();
         if ($content) {
             $requestData = \Zend_Json::decode($content);
         }
         $isRememberMeChecked = empty($requestData['persistent_remember_me']) ? false : true;
         $this->_persistentSession->setRememberMeChecked((bool) $isRememberMeChecked);
     }
 }
 /**
  * @covers \Magento\Persistent\Observer\SynchronizePersistentOnLoginObserver::execute
  */
 public function testSynchronizePersistentOnLogin()
 {
     $event = new \Magento\Framework\Event();
     $observer = new \Magento\Framework\Event\Observer(['event' => $event]);
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = $this->_objectManager->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     /** @var $customer \Magento\Customer\Api\Data\CustomerInterface */
     $customer = $customerRepository->getById(1);
     $event->setData('customer', $customer);
     $this->_persistentSession->setRememberMeChecked(true);
     $this->_model->execute($observer);
     // check that persistent session has been stored for Customer
     /** @var \Magento\Persistent\Model\Session $sessionModel */
     $sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session');
     $sessionModel->loadByCustomerId(1);
     $this->assertEquals(1, $sessionModel->getCustomerId());
 }
Example #5
0
 /**
  * @covers \Magento\Persistent\Model\Observer\Session::synchronizePersistentOnLogin
  */
 public function testSynchronizePersistentOnLogin()
 {
     $event = new \Magento\Framework\Event();
     $observer = new \Magento\Framework\Event\Observer(array('event' => $event));
     /** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerAccountService */
     $customerAccountService = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     /** @var $customer \Magento\Customer\Service\V1\Data\Customer */
     $customer = $customerAccountService->getCustomer(1);
     $event->setData('customer', $customer);
     $this->_persistentSession->setRememberMeChecked(true);
     $this->_cookieMock->expects($this->once())->method('set')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $this->anything(), $this->anything(), $this->_customerSession->getCookiePath());
     $this->_model->synchronizePersistentOnLogin($observer);
     // check that persistent session has been stored for Customer
     /** @var \Magento\Persistent\Model\Session $sessionModel */
     $sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session');
     $sessionModel->loadByCustomerId(1);
     $this->assertEquals(1, $sessionModel->getCustomerId());
 }