Beispiel #1
0
 /**
  * @param \Magento\Store\Model\StoreManagerInterface $storage
  * @param string $scopeType
  * @return void
  */
 protected function _checkCookieStore(\Magento\Store\Model\StoreManagerInterface $storage, $scopeType)
 {
     $storeCode = $this->_cookieManager->getCookie(Store::COOKIE_NAME);
     if (isset($storeCode)) {
         $this->setCurrentStore($storage, $storeCode, $scopeType);
     }
 }
Beispiel #2
0
 /**
  * Try to load valid order by $_POST or $_COOKIE
  *
  * @param App\RequestInterface $request
  * @param App\ResponseInterface $response
  * @return bool
  * 
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 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();
     $fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME);
     if (empty($post) && !$fromCookie) {
         $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->setGuestViewCookie($toCookie);
         }
     } elseif ($fromCookie) {
         $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) {
                 // renew cookie
                 $this->setGuestViewCookie($fromCookie);
                 $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;
 }
Beispiel #3
0
 /**
  * Postpone cookie expiration time if cookie value defined
  *
  * @param int $duration Time in seconds.
  * @param string $path
  * @return $this
  */
 public function renewPersistentCookie($duration, $path)
 {
     if ($duration === null) {
         return $this;
     }
     $value = $this->_cookieManager->getCookie(self::COOKIE_NAME);
     if (null !== $value) {
         $this->setCookie($value, $duration, $path);
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Postpone cookie expiration time if cookie value defined
  *
  * @param int $duration Time in seconds.
  * @param string $path
  * @return $this
  */
 public function renewPersistentCookie($duration, $path)
 {
     if ($duration === null) {
         return $this;
     }
     $value = $this->_cookieManager->getCookie(self::COOKIE_NAME);
     if (null !== $value) {
         $publicCookieMetadata = $this->_cookieMetadataFactory->createPublicCookieMetadata()->setDuration($duration)->setPath($path);
         $this->_cookieManager->setPublicCookie(self::COOKIE_NAME, $value, $publicCookieMetadata);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Get store code from store cookie.
  *
  * @return null|string
  */
 public function getStoreCodeFromCookie()
 {
     return $this->_cookieManager->getCookie(self::COOKIE_NAME);
 }
Beispiel #6
0
 /**
  * Return count of sent in last period by cookie
  *
  * @param bool $increment - flag, increase count before return value
  * @return int
  */
 protected function _sentCountByCookies($increment = false)
 {
     $cookieName = $this->_sendfriendData->getCookieName();
     $time = time();
     $newTimes = array();
     if (isset($this->_lastCookieValue[$cookieName])) {
         $oldTimes = $this->_lastCookieValue[$cookieName];
     } else {
         $oldTimes = $this->cookieManager->getCookie($cookieName);
     }
     if ($oldTimes) {
         $oldTimes = explode(',', $oldTimes);
         foreach ($oldTimes as $oldTime) {
             $periodTime = $time - $this->_sendfriendData->getPeriod();
             if (is_numeric($oldTime) and $oldTime >= $periodTime) {
                 $newTimes[] = $oldTime;
             }
         }
     }
     if ($increment) {
         $newTimes[] = $time;
         $newValue = implode(',', $newTimes);
         $this->cookieManager->setSensitiveCookie($cookieName, $newValue);
         $this->_lastCookieValue[$cookieName] = $newValue;
     }
     return count($newTimes);
 }
Beispiel #7
0
 /**
  * Get products per page limit
  *
  * @return string|bool
  */
 public function getLimit()
 {
     return $this->cookieManager->getCookie(self::LIMIT_COOKIE_NAME);
 }
Beispiel #8
0
 /**
  * Retrieve a value from a cookie.
  *
  * @param string|null $name
  * @param string|null $default The default value to return if no value could be found for the given $name.
  * @return string|null
  */
 public function getCookie($name = null, $default = null)
 {
     return $this->_cookieManager->getCookie($name, $default);
 }
Beispiel #9
0
 /**
  * @param \Magento\Framework\App\Action\Action $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  */
 public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_CURRENCY, $this->session->getCurrencyCode(), $this->storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode());
     $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_STORE, $this->httpRequest->getParam('___store', $this->cookieManager->getCookie(\Magento\Store\Model\Store::COOKIE_NAME)), $this->storeManager->getWebsite()->getDefaultStore()->getCode());
     return $proceed($request);
 }