Skip to content

Commit

Permalink
fix(CP): ES-156 Fixed the filtering issues with price range filter se…
Browse files Browse the repository at this point in the history
…lection.
  • Loading branch information
bc-krishsenthilraj committed Apr 10, 2019
1 parent d5a1b56 commit affa3ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
13 changes: 10 additions & 3 deletions assets/js/theme/common/faceted-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,17 @@ class FacetedSearch {
return;
}

const url = Url.parse(window.location.href);
const queryParams = decodeURI($(event.currentTarget).serialize());
const url = Url.parse(window.location.href, true);
let queryParams = decodeURI($(event.currentTarget).serialize()).split('&');
queryParams = urlUtils.parseQueryParams(queryParams);

urlUtils.goToUrl(Url.format({ pathname: url.pathname, search: `?${queryParams}` }));
for (const key in queryParams) {
if (queryParams.hasOwnProperty(key)) {
url.query[key] = queryParams[key];
}
}

urlUtils.goToUrl(Url.format({ pathname: url.pathname, search: urlUtils.buildQueryString(url.query) }));
}

onStateChange() {
Expand Down
20 changes: 20 additions & 0 deletions assets/js/theme/common/url-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ const urlUtils = {

return out.substring(1);
},

parseQueryParams: (queryData) => {
const params = {};

for (let i = 0; i < queryData.length; i++) {
const temp = queryData[i].split('=');

if (temp[0] in params) {
if (Array.isArray(params[temp[0]])) {
params[temp[0]].push(temp[1]);
} else {
params[temp[0]] = [params[temp[0]], temp[1]];
}
} else {
params[temp[0]] = temp[1];
}
}

return params;
},
};

export default urlUtils;

0 comments on commit affa3ca

Please sign in to comment.