Skip to content

Commit

Permalink
MAGETWO-72254: Backport PR-9713 for Magento 2.1 - stringify cookie va…
Browse files Browse the repository at this point in the history
…lue to fix #5596 #10749
  • Loading branch information
ishakhsuvarov authored Sep 8, 2017
2 parents 8390ef4 + f200327 commit 0eaa3da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 12 additions & 1 deletion app/code/Magento/Cookie/Helper/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,22 @@ public function __construct(
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
*/
public function isCookieRestrictionModeEnabled()
{
return $this->scopeConfig->getValue(
self::XML_PATH_COOKIE_RESTRICTION,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->_currentStore
) && empty($acceptedSaveCookiesWebsites[$this->_website->getId()]);
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

?>
<?php /** @var \Magento\Cookie\Block\Html\Notices $block */ ?>
<?php if ($this->helper('Magento\Cookie\Helper\Cookie')->isUserNotAllowSaveCookie()): ?>
<?php if ($this->helper('Magento\Cookie\Helper\Cookie')->isCookieRestrictionModeEnabled()): ?>
<div class="message global cookie" id="notice-cookie-block" style="display: none">
<div class="content">
<p>
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/Cookie/view/frontend/web/js/notices.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ define([
$(this.options.cookieAllowButtonSelector).on('click', $.proxy(function() {
var cookieExpires = new Date(new Date().getTime() + this.options.cookieLifetime * 1000);

$.mage.cookies.set(this.options.cookieName, this.options.cookieValue, {expires: cookieExpires});
$.mage.cookies.set(this.options.cookieName, JSON.stringify(this.options.cookieValue), {
expires: cookieExpires
});

if ($.mage.cookies.get(this.options.cookieName)) {
window.location.reload();
} else {
Expand Down

0 comments on commit 0eaa3da

Please sign in to comment.