/** * get FB cookie * @param CookieManagerInterface $cookieManager * @param CookieMetadataFactory $cookieMetadataFactory * @param \BelVG\FacebookFree\Helper\Data $dataHelper */ public function __construct(CookieManagerInterface $cookieManager, CookieMetadataFactory $cookieMetadataFactory, \BelVG\FacebookFree\Helper\Data $dataHelper) { $this->cookieManager = $cookieManager; $this->cookieMetadataFactory = $cookieMetadataFactory; $this->dataHelper = $dataHelper; $cookieName = self::FB_COOKIE_PREFIX . $this->dataHelper->getAppId(); $this->fbCookie = $this->cookieManager->getCookie($cookieName); }
/** * get user code. * * @param mixed $id * * @return string */ protected function getUserCode($id) { $ipAddress = $this->_phpEnvironmentRequest->getClientIp(true); $cookiefrontend = $this->_cookieManager->getCookie('frontend'); $usercode = $ipAddress . $cookiefrontend . $id; return md5($usercode); }
/** * Try to load valid order by $_POST or $_COOKIE * * @param App\RequestInterface $request * @return \Magento\Framework\Controller\Result\Redirect|bool * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function loadValidOrder(App\RequestInterface $request) { if ($this->customerSession->isLoggedIn()) { return $this->resultRedirectFactory->create()->setPath('sales/order/history'); } $post = $request->getPostValue(); $errors = false; /** @var $order \Magento\Sales\Model\Order */ $order = $this->orderFactory->create(); $fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME); if (empty($post) && !$fromCookie) { return $this->resultRedirectFactory->create()->setPath('sales/guest/form'); } 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']; $storeId = $this->_storeManager->getStore()->getId(); if (empty($incrementId) || empty($lastName) || empty($type) || empty($storeId) || !in_array($type, ['email', 'zip']) || $type == 'email' && empty($email) || $type == 'zip' && empty($zip)) { $errors = true; } if (!$errors) { $order = $order->loadByIncrementIdAndStoreId($incrementId, $storeId); } $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.')); return $this->resultRedirectFactory->create()->setPath('sales/guest/form'); }
/** * 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; }
/** @inheritdoc */ public function processHttpRequest($getVar) { /* get code from cookie */ $cookie = $this->_cookieManager->getCookie(static::COOKIE_REFERRAL_CODE); $voCookie = new ReferralCookie($cookie); /* replace cookie value if GET code is not equal to cookie value */ if ($getVar && $getVar != $voCookie->getCode()) { $tsSaved = $this->_toolDate->getUtcNow(); $saved = $tsSaved->format('Ymd'); $voCookie->setCode($getVar); $voCookie->setDateSaved($saved); $cookie = $voCookie->generateCookieValue(); $meta = new \Magento\Framework\Stdlib\Cookie\PublicCookieMetadata(); $meta->setPath('/'); $meta->setDurationOneYear(); $this->_cookieManager->setPublicCookie(static::COOKIE_REFERRAL_CODE, $cookie, $meta); } /* save referral code into the registry */ $code = $voCookie->getCode(); $this->replaceCodeInRegistry($code); }
/** * Return messages stored in cookies * * @return array */ protected function getCookiesMessages() { try { $messages = $this->jsonHelper->jsonDecode($this->cookieManager->getCookie(self::MESSAGES_COOKIES_NAME, $this->jsonHelper->jsonEncode([]))); if (!is_array($messages)) { $messages = []; } } catch (\Zend_Json_Exception $e) { $messages = []; } return $messages; }
/** * Get store code from store cookie. * * @return null|string */ public function getStoreCodeFromCookie() { return $this->_cookieManager->getCookie(self::COOKIE_NAME); }
/** * 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 = []; 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); }
/** * Get form key cookie * * @return string */ public function get() { return $this->cookieManager->getCookie(self::COOKIE_NAME); }