/** * Handle private content version cookie * Set cookie if it is not set. * Increment version on post requests. * In all other cases do nothing. * * @return void */ public function process() { if ($this->request->isPost()) { $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false); $this->cookieManager->setPublicCookie(self::COOKIE_NAME, $this->generateValue(), $publicCookieMetadata); } }
/** * Set Cookie for msg box when it displays first * * @param FrontController $subject * @param \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface $result * * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDispatch(FrontController $subject, $result) { if ($this->request->isPost() && $this->messageManager->hasMessages()) { $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false); $this->cookieManager->setPublicCookie(self::COOKIE_NAME, 1, $publicCookieMetadata); } return $result; }
/** * @param ResultInterface $subject * @param ResultInterface $result * @return ResultInterface */ public function afterRenderResult(ResultInterface $subject, ResultInterface $result) { if (!$subject instanceof Json) { $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata(); $publicCookieMetadata->setDurationOneYear(); $publicCookieMetadata->setPath('/'); $publicCookieMetadata->setHttpOnly(false); $this->cookieManager->setPublicCookie(self::MESSAGES_COOKIES_NAME, $this->jsonHelper->jsonEncode($this->getMessages()), $publicCookieMetadata); } return $result; }
/** @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); }
/** * Set persistent shopping cart cookie. * * @param string $value * @param int $duration * @param string $path * @return void */ private function setCookie($value, $duration, $path) { $publicCookieMetadata = $this->_cookieMetadataFactory->createPublicCookieMetadata()->setDuration($duration)->setPath($path)->setHttpOnly(true); $this->_cookieManager->setPublicCookie(self::COOKIE_NAME, $value, $publicCookieMetadata); }
/** * Set store cookie with this store's code for a year. * * @return $this */ public function setCookie() { $cookieMetadata = $this->_cookieMetadataFactory->createPublicCookieMetadata()->setHttpOnly(true)->setDurationOneYear()->setPath($this->getStorePath()); $this->_cookieManager->setPublicCookie(self::COOKIE_NAME, $this->getCode(), $cookieMetadata); return $this; }
/** * {@inheritdoc} */ public function setStoreCookie(StoreInterface $store) { $cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setHttpOnly(true)->setDurationOneYear()->setPath($store->getStorePath()); $this->cookieManager->setPublicCookie(self::COOKIE_NAME, $store->getCode(), $cookieMetadata); }
/** * @param string $value * @param PublicCookieMetadata $metadata * @return void */ public function set($value, PublicCookieMetadata $metadata) { $this->cookieManager->setPublicCookie(self::COOKIE_NAME, $value, $metadata); }
/** * Set guest-view cookie * * @param string $cookieValue * @return void */ private function setGuestViewCookie($cookieValue) { $metadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setPath(self::COOKIE_PATH)->setHttpOnly(true); $this->cookieManager->setPublicCookie(self::COOKIE_NAME, $cookieValue, $metadata); }
/** * @todo move Cookie base functions to separate Cookie class * @param $value */ public function setDebugCookie($value) { $publicCookieMetadata = $this->_cookieMetadataFactory->createPublicCookieMetadata(); $this->_cookieManager->setPublicCookie(self::COOKIE_NAME, $value, $publicCookieMetadata); }