/** * 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); } }
/** * @param \Magento\Store\Model\StoreManagerInterface $storage * @param string $scopeType * @return void */ protected function _checkRequestStore(\Magento\Store\Model\StoreManagerInterface $storage, $scopeType) { $storeCode = $this->request->getParam('___store'); if (empty($storeCode)) { return; } if (!$this->setCurrentStore($storage, $storeCode, $scopeType)) { return; } if ($storage->getStore()->getCode() == $storeCode) { $store = $storage->getStore($storeCode); if ($store->getWebsite()->getDefaultStore()->getId() == $store->getId()) { $this->_cookieManager->deleteCookie(Store::COOKIE_NAME); } else { $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDurationOneYear(); $this->_cookieManager->setPublicCookie(Store::COOKIE_NAME, $storage->getStore()->getCode(), $publicCookieMetadata); $this->_httpContext->setValue(Store::ENTITY, $storage->getStore()->getCode(), \Magento\Store\Model\Store::DEFAULT_CODE); } } return; }
/** * Delete store cookie. * * @return $this */ public function deleteCookie() { $this->_cookieManager->deleteCookie(self::COOKIE_NAME); return $this; }
/** * Expire the session cookie * * Sends a session cookie with no value, and with an expiry in the past. * * @return void */ public function expireSessionCookie() { if (!$this->sessionConfig->getUseCookies()) { return; } $metadata = $this->cookieMetadataFactory->createPublicCookieMetadata(); $metadata->setPath($this->sessionConfig->getCookiePath()); $metadata->setDomain($this->sessionConfig->getCookieDomain()); $metadata->setSecure($this->sessionConfig->getCookieSecure()); $metadata->setHttpOnly($this->sessionConfig->getCookieHttpOnly()); $this->cookieManager->deleteCookie($this->getName(), $metadata); $this->clearSubDomainSessionCookie(); }
/** * 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; }
/** * Remove persistent cookie * * @return $this */ public function removePersistentCookie() { $cookieMetadata = $this->_cookieMetadataFactory->createCookieMetadata()->setPath($this->sessionConfig->getCookiePath()); $this->_cookieManager->deleteCookie(self::COOKIE_NAME, $cookieMetadata); return $this; }