_currentStore = isset($data['current_store']) ? $data['current_store'] : $storeManager->getStore(); if (!$this->_currentStore instanceof \Magento\Store\Model\Store) { throw new \InvalidArgumentException('Required store object is invalid'); } $this->_website = isset($data['website']) ? $data['website'] : $storeManager->getWebsite(); if (!$this->_website instanceof \Magento\Store\Model\Website) { throw new \InvalidArgumentException('Required website object is invalid'); } } /** * Check if cookie restriction notice should be displayed * * @return bool */ public function isUserNotAllowSaveCookie() { $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites(); return $this->isCookieRestrictionModeEnabled() && empty($acceptedSaveCookiesWebsites[$this->_website->getId()]); } /** * Check if cookie restriction mode is enabled for this store * * @return bool * @since 100.1.3 */ public function isCookieRestrictionModeEnabled() { return $this->scopeConfig->getValue( self::XML_PATH_COOKIE_RESTRICTION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->_currentStore ); } /** * Return serialized list of accepted save cookie website * * @return string */ public function getAcceptedSaveCookiesWebsiteIds() { $acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites(); $acceptedSaveCookiesWebsites[(int)$this->_website->getId()] = 1; return json_encode($acceptedSaveCookiesWebsites); } /** * Get accepted save cookies websites * * @return array */ protected function _getAcceptedSaveCookiesWebsites() { $unSerializedList = null; $serializedList = $this->_request->getCookie(self::IS_USER_ALLOWED_SAVE_COOKIE, false); if ($serializedList) { $unSerializedList = json_decode($serializedList, true); } return is_array($unSerializedList) ? $unSerializedList : []; } /** * Get cookie restriction lifetime (in seconds) * * @return int */ public function getCookieRestrictionLifetime() { return (int)$this->scopeConfig->getValue( self::XML_PATH_COOKIE_RESTRICTION_LIFETIME, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->_currentStore ); } }