5
5
use Algolia \AlgoliaSearch \Helper \Configuration \PersonalizationHelper ;
6
6
use Algolia \AlgoliaSearch \Insights \UserInsightsClient ;
7
7
use Algolia \AlgoliaSearch \InsightsClient ;
8
+ use Magento \Customer \Model \Customer ;
8
9
use Magento \Customer \Model \Session as CustomerSession ;
10
+ use Magento \Framework \Session \SessionManagerInterface ;
9
11
use Magento \Framework \Stdlib \Cookie \CookieMetadataFactory ;
10
12
use Magento \Framework \Stdlib \CookieManagerInterface ;
11
13
@@ -48,12 +50,14 @@ class InsightsHelper
48
50
public function __construct (
49
51
ConfigHelper $ configHelper ,
50
52
PersonalizationHelper $ personalizationHelper ,
53
+ SessionManagerInterface $ sessionManager ,
51
54
CookieManagerInterface $ cookieManager ,
52
55
CookieMetadataFactory $ cookieMetadataFactory ,
53
56
CustomerSession $ customerSession
54
57
) {
55
58
$ this ->configHelper = $ configHelper ;
56
59
$ this ->personalizationHelper = $ personalizationHelper ;
60
+ $ this ->sessionManager = $ sessionManager ;
57
61
$ this ->cookieManager = $ cookieManager ;
58
62
$ this ->cookieMetadataFactory = $ cookieMetadataFactory ;
59
63
$ this ->customerSession = $ customerSession ;
@@ -142,11 +146,11 @@ private function getUserToken()
142
146
}
143
147
144
148
/**
145
- * @param \Magento\Customer\Model\ Customer $customer
149
+ * @param Customer $customer
146
150
*
147
151
* @return string
148
152
*/
149
- public function setUserToken (\ Magento \ Customer \ Model \ Customer $ customer )
153
+ public function setUserToken (Customer $ customer )
150
154
{
151
155
$ userToken = base64_encode ('customer- ' . $ customer ->getEmail () . '- ' . $ customer ->getId ());
152
156
$ userToken = 'aa- ' . preg_replace ('/[^A-Za-z0-9\-]/ ' , '' , $ userToken );
@@ -166,4 +170,18 @@ public function setUserToken(\Magento\Customer\Model\Customer $customer)
166
170
167
171
return $ userToken ;
168
172
}
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
+ }
169
187
}
0 commit comments