Skip to content

Commit bbe8ec9

Browse files
committed
MAGE-787 Fixed issue with cookies not cleared when customer logs out
1 parent 93465eb commit bbe8ec9

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Helper/InsightsHelper.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Algolia\AlgoliaSearch\Helper\Configuration\PersonalizationHelper;
66
use Algolia\AlgoliaSearch\Insights\UserInsightsClient;
77
use Algolia\AlgoliaSearch\InsightsClient;
8+
use Magento\Customer\Model\Customer;
89
use Magento\Customer\Model\Session as CustomerSession;
10+
use Magento\Framework\Session\SessionManagerInterface;
911
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1012
use Magento\Framework\Stdlib\CookieManagerInterface;
1113

@@ -48,12 +50,14 @@ class InsightsHelper
4850
public function __construct(
4951
ConfigHelper $configHelper,
5052
PersonalizationHelper $personalizationHelper,
53+
SessionManagerInterface $sessionManager,
5154
CookieManagerInterface $cookieManager,
5255
CookieMetadataFactory $cookieMetadataFactory,
5356
CustomerSession $customerSession
5457
) {
5558
$this->configHelper = $configHelper;
5659
$this->personalizationHelper = $personalizationHelper;
60+
$this->sessionManager = $sessionManager;
5761
$this->cookieManager = $cookieManager;
5862
$this->cookieMetadataFactory = $cookieMetadataFactory;
5963
$this->customerSession = $customerSession;
@@ -142,11 +146,11 @@ private function getUserToken()
142146
}
143147

144148
/**
145-
* @param \Magento\Customer\Model\Customer $customer
149+
* @param Customer $customer
146150
*
147151
* @return string
148152
*/
149-
public function setUserToken(\Magento\Customer\Model\Customer $customer)
153+
public function setUserToken(Customer $customer)
150154
{
151155
$userToken = base64_encode('customer-' . $customer->getEmail() . '-' . $customer->getId());
152156
$userToken = 'aa-' . preg_replace('/[^A-Za-z0-9\-]/', '', $userToken);
@@ -171,6 +175,20 @@ public function setUserToken(\Magento\Customer\Model\Customer $customer)
171175
* @return string|null
172176
*/
173177
public function getUserAllowedSavedCookie() {
174-
return $this->configHelper->isCookieRestrictionModeEnabled() ? !!$this->cookieManager->getCookie('user_allowed_save_cookie') : true;
178+
return $this->configHelper->isCookieRestrictionModeEnabled() ? !!$this->cookieManager->getCookie($this->configHelper->getDefaultConsentCookieName()) : true;
179+
}
180+
181+
/**
182+
* @param Customer $customer
183+
* @return void
184+
*/
185+
public function unsetUserToken(Customer $customer)
186+
{
187+
if ($this->cookieManager->getCookie(self::ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME)) {
188+
$metadata = $this->cookieMetadataFactory->createCookieMetadata()
189+
->setPath($this->sessionManager->getCookiePath());
190+
return $this->cookieManager->deleteCookie(
191+
self::ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME,$metadata);
192+
}
175193
}
176194
}

0 commit comments

Comments
 (0)