Skip to content

Commit 584c0ed

Browse files
committed
MAGE-787 Fixed issue with cookies not cleared when customer logs out
1 parent b3b50e3 commit 584c0ed

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Helper/InsightsHelper.php

Lines changed: 20 additions & 2 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);
@@ -166,4 +170,18 @@ public function setUserToken(\Magento\Customer\Model\Customer $customer)
166170

167171
return $userToken;
168172
}
173+
174+
/**
175+
* @param Customer $customer
176+
* @return void
177+
*/
178+
public function unsetUserToken(Customer $customer)
179+
{
180+
if ($this->cookieManager->getCookie(self::ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME)) {
181+
$metadata = $this->cookieMetadataFactory->createCookieMetadata()
182+
->setPath($this->sessionManager->getCookiePath());
183+
return $this->cookieManager->deleteCookie(
184+
self::ALGOLIA_CUSTOMER_USER_TOKEN_COOKIE_NAME,$metadata);
185+
}
186+
}
169187
}

0 commit comments

Comments
 (0)