|
1 |
| -define(['jquery', 'algoliaInstantSearchLib', 'algoliaBase64'], function ($, instantsearch, algoliaBase64) { |
| 1 | +define(['jquery', 'algoliaInstantSearchLib', 'algoliaBase64', 'Magento_PageCache/js/form-key-provider'], function ($, instantsearch, algoliaBase64) { |
2 | 2 | const USE_GLOBALS = true;
|
3 | 3 |
|
4 | 4 | // Character maps supplied for more performant Regex ops
|
@@ -243,23 +243,36 @@ define(['jquery', 'algoliaInstantSearchLib', 'algoliaBase64'], function ($, inst
|
243 | 243 | const mobileRegex = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini|mobile/i;
|
244 | 244 | return mobileRegex.test(navigator.userAgent);
|
245 | 245 | },
|
246 |
| - |
| 246 | + |
247 | 247 | isTouchDevice: () => {
|
248 | 248 | return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
249 | 249 | }
|
250 | 250 | };
|
251 |
| - |
| 251 | + |
252 | 252 | const legacyGlobalFunctions = {
|
253 | 253 | isMobile: () => {
|
254 | 254 | return utils.isMobileUserAgent() || utils.isTouchDevice();
|
255 | 255 | },
|
256 | 256 |
|
257 | 257 | getCookie: (name) => {
|
258 |
| - const value = `; ${document.cookie}`; |
259 |
| - const parts = value.split(`; ${name}=`); |
260 |
| - return (parts.length === 2) |
261 |
| - ? parts.pop().split(';').shift() |
262 |
| - : ''; |
| 258 | + let cookie, i; |
| 259 | + |
| 260 | + const cookieName = name + "=", |
| 261 | + cookieArr = document.cookie.split(';'); |
| 262 | + |
| 263 | + for (i = 0; i < cookieArr.length; i++) { |
| 264 | + cookie = cookieArr[i]; |
| 265 | + |
| 266 | + while (cookie.charAt(0) === ' ') { |
| 267 | + cookie = cookie.substring(1, cookie.length); |
| 268 | + } |
| 269 | + |
| 270 | + if (cookie.indexOf(cookieName) === 0) { |
| 271 | + return cookie.substring(cookieName.length, cookie.length); |
| 272 | + } |
| 273 | + } |
| 274 | + |
| 275 | + return ""; |
263 | 276 | },
|
264 | 277 |
|
265 | 278 | // @deprecated This function will be removed from this module in a future version
|
@@ -365,27 +378,23 @@ define(['jquery', 'algoliaInstantSearchLib', 'algoliaBase64'], function ($, inst
|
365 | 378 | }
|
366 | 379 | hit._highlightResult.default_bundle_options = default_bundle_option;
|
367 | 380 | }
|
368 |
| - |
| 381 | + |
369 | 382 | // Add to cart parameters
|
370 | 383 | var action = algoliaConfig.instant.addToCartParams.action + 'product/' + hit.objectID + '/';
|
371 |
| - |
372 |
| - var correctFKey = this.getCookie('form_key'); |
373 |
| - |
374 |
| - if (correctFKey != "" && algoliaConfig.instant.addToCartParams.formKey != correctFKey) { |
375 |
| - algoliaConfig.instant.addToCartParams.formKey = correctFKey; |
376 |
| - } |
377 |
| - |
| 384 | + |
| 385 | + algoliaConfig.instant.addToCartParams.formKey = getCookie('form_key'); |
| 386 | + |
378 | 387 | hit.addToCart = {
|
379 | 388 | 'action': action,
|
380 | 389 | 'redirectUrlParam': algoliaConfig.instant.addToCartParams.redirectUrlParam,
|
381 | 390 | 'uenc': algoliaBase64.mageEncode(action),
|
382 | 391 | 'formKey': algoliaConfig.instant.addToCartParams.formKey
|
383 | 392 | };
|
384 |
| - |
| 393 | + |
385 | 394 | if (hit.__queryID) {
|
386 |
| - |
| 395 | + |
387 | 396 | hit.urlForInsights = hit.url;
|
388 |
| - |
| 397 | + |
389 | 398 | if (algoliaConfig.ccAnalytics.enabled
|
390 | 399 | && algoliaConfig.ccAnalytics.conversionAnalyticsMode !== 'disabled') {
|
391 | 400 | var insightsDataUrlString = $.param({
|
|
0 commit comments