예제 #1
0
 /**
  * @param \Magento\Store\Model\StoreManagerInterface $storage
  * @param string $scopeType
  * @return void
  */
 protected function _checkCookieStore(\Magento\Store\Model\StoreManagerInterface $storage, $scopeType)
 {
     if (!$this->_cookie->get()) {
         return;
     }
     $storeCode = $this->_cookie->get(Store::COOKIE_NAME);
     $this->setCurrentStore($storage, $storeCode, $scopeType);
 }
예제 #2
0
 /**
  * Try to load valid order by $_POST or $_COOKIE
  *
  * @param App\RequestInterface $request
  * @param App\ResponseInterface $response
  * @return bool
  */
 public function loadValidOrder(App\RequestInterface $request, App\ResponseInterface $response)
 {
     if ($this->_customerSession->isLoggedIn()) {
         $response->setRedirect($this->_urlBuilder->getUrl('sales/order/history'));
         return false;
     }
     $post = $request->getPost();
     $errors = false;
     /** @var $order \Magento\Sales\Model\Order */
     $order = $this->_orderFactory->create();
     if (empty($post) && !$this->_coreCookie->get(self::COOKIE_NAME)) {
         $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form'));
         return false;
     } elseif (!empty($post) && isset($post['oar_order_id']) && isset($post['oar_type'])) {
         $type = $post['oar_type'];
         $incrementId = $post['oar_order_id'];
         $lastName = $post['oar_billing_lastname'];
         $email = $post['oar_email'];
         $zip = $post['oar_zip'];
         if (empty($incrementId) || empty($lastName) || empty($type) || !in_array($type, array('email', 'zip')) || $type == 'email' && empty($email) || $type == 'zip' && empty($zip)) {
             $errors = true;
         }
         if (!$errors) {
             $order->loadByIncrementId($incrementId);
         }
         $errors = true;
         if ($order->getId()) {
             $billingAddress = $order->getBillingAddress();
             if (strtolower($lastName) == strtolower($billingAddress->getLastname()) && ($type == 'email' && strtolower($email) == strtolower($billingAddress->getEmail()) || $type == 'zip' && strtolower($zip) == strtolower($billingAddress->getPostcode()))) {
                 $errors = false;
             }
         }
         if (!$errors) {
             $toCookie = base64_encode($order->getProtectCode() . ':' . $incrementId);
             $this->_coreCookie->set(self::COOKIE_NAME, $toCookie, self::COOKIE_LIFETIME, self::COOKIE_PATH);
         }
     } elseif ($this->_coreCookie->get(self::COOKIE_NAME)) {
         $fromCookie = $this->_coreCookie->get(self::COOKIE_NAME);
         $cookieData = explode(':', base64_decode($fromCookie));
         $protectCode = isset($cookieData[0]) ? $cookieData[0] : null;
         $incrementId = isset($cookieData[1]) ? $cookieData[1] : null;
         $errors = true;
         if (!empty($protectCode) && !empty($incrementId)) {
             $order->loadByIncrementId($incrementId);
             if ($order->getProtectCode() == $protectCode) {
                 $this->_coreCookie->renew(self::COOKIE_NAME, self::COOKIE_LIFETIME, self::COOKIE_PATH);
                 $errors = false;
             }
         }
     }
     if (!$errors && $order->getId()) {
         $this->_coreRegistry->register('current_order', $order);
         return true;
     }
     $this->messageManager->addError(__('You entered incorrect data. Please try again.'));
     $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form'));
     return false;
 }
예제 #3
0
 /**
  * Get persistent session by cookie key
  *
  * @param string $key
  * @return $this
  */
 public function loadByCookieKey($key = null)
 {
     if (null === $key) {
         $key = $this->_cookie->get(self::COOKIE_NAME);
     }
     if ($key) {
         $this->load($key, 'key');
     }
     return $this;
 }
예제 #4
0
 /**
  * Set session UpdatedAt to current time and update cookie expiration time
  *
  * @return void
  */
 public function prolong()
 {
     $lifetime = $this->_config->getValue(self::XML_PATH_SESSION_LIFETIME);
     $currentTime = time();
     $this->setUpdatedAt($currentTime);
     $cookieValue = $this->_cookie->get($this->getName());
     if ($cookieValue) {
         $this->_cookie->set($this->getName(), $cookieValue, $lifetime, $this->sessionConfig->getCookiePath(), $this->sessionConfig->getCookieDomain(), $this->sessionConfig->getCookieSecure(), $this->sessionConfig->getCookieHttpOnly());
     }
 }
예제 #5
0
 /**
  * Get products per page limit
  *
  * @return string|bool
  */
 public function getLimit()
 {
     return $this->cookie->get(self::LIMIT_COOKIE_NAME);
 }
예제 #6
0
 /**
  * Get form key cookie
  *
  * @return string
  */
 public function get()
 {
     return $this->cookie->get(self::COOKIE_NAME);
 }