Skip to content

Commit caa488b

Browse files
committed
MAGETWO-87815: Update PAT scenarios for caching popular search terms functionality
1 parent dadd4c5 commit caa488b

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

app/code/Magento/CatalogSearch/view/frontend/web/js/search-terms-log.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,17 @@
44
*/
55

66
define([
7-
'jquery'
8-
], function ($) {
7+
'jquery',
8+
'mageUtils'
9+
], function ($, utils) {
910
'use strict';
1011

11-
/**
12-
* Return url parameters.
13-
* @returns {Object}
14-
*/
15-
function urlParameters() {
16-
var params = {},
17-
queries = window.location.search.substring(1).split('&'),
18-
temp,
19-
i,
20-
l;
21-
22-
for (i = 0, l = queries.length; i < l; i++) {
23-
temp = queries[i].split('=');
24-
params[temp[0]] = temp[1];
25-
}
26-
27-
return params;
28-
}
29-
3012
return function (data) {
3113
$.ajax({
3214
method: 'GET',
3315
url: data.url,
3416
data: {
35-
'q': decodeURIComponent(urlParameters().q.replace(/\+/g, '%20'))
17+
'q': utils.getUrlParameters(window.location.href).q
3618
}
3719
});
3820
};

lib/web/mage/utils/misc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,27 @@ define([
255255
newFormat = newFormat.replace(/dd|d/g, 'DD'); // replace the date
256256

257257
return newFormat;
258+
},
259+
260+
/**
261+
* Get Url Parameters.
262+
*
263+
* @param {String} url - Url string
264+
* @returns {Object}
265+
*/
266+
getUrlParameters: function (url) {
267+
var params = {},
268+
queries = url.split('?')[1].split('&'),
269+
temp,
270+
i,
271+
l;
272+
273+
for (i = 0, l = queries.length; i < l; i++) {
274+
temp = queries[i].split('=');
275+
params[temp[0]] = decodeURIComponent(temp[1].replace(/\+/g, '%20'));
276+
}
277+
278+
return params;
258279
}
259280
};
260281
});

0 commit comments

Comments
 (0)