/** * Send Vary coookie * * @return void */ public function sendVary() { $data = $this->context->getData(); if (!empty($data)) { ksort($data); $cookieValue = sha1(serialize($data)); $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/'); $this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $cookieValue, $sensitiveCookMetadata); } else { $cookieMetadata = $this->cookieMetadataFactory->createCookieMetadata()->setPath('/'); $this->cookieManager->deleteCookie(self::COOKIE_VARY_STRING, $cookieMetadata); } }
/** * 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); }
/** * Set current store currency code * * @param string $code * @return string */ public function setCurrentCurrencyCode($code) { $code = strtoupper($code); if (in_array($code, $this->getAvailableCurrencyCodes())) { $this->_getSession()->setCurrencyCode($code); $path = $this->_getSession()->getCookiePath(); $sensitiveCookieMetadata = $this->_cookieMetadataFactory->createSensitiveCookieMetadata()->setPath($path); if ($code == $this->getDefaultCurrency()->getCurrencyCode()) { $this->_cookieManager->deleteCookie(self::COOKIE_CURRENCY, $sensitiveCookieMetadata); } else { $this->_cookieManager->setSensitiveCookie(self::COOKIE_CURRENCY, $code, $sensitiveCookieMetadata); } $this->_httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_CURRENCY, $code, $this->_storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode()); } return $this; }