diff --git a/app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js b/app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js index 6589f7eb0ba48..41f670ecb082d 100644 --- a/app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js +++ b/app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js @@ -80,25 +80,49 @@ define([ ); }, - /** - * @param {String} paramName - * @param {*} paramValue - * @param {*} defaultValue - */ - changeUrl: function (paramName, paramValue, defaultValue) { + getUrlParams: function() { var decode = window.decodeURIComponent, urlPaths = this.options.url.split('?'), - baseUrl = urlPaths[0], urlParams = urlPaths[1] ? urlPaths[1].split('&') : [], - paramData = {}, - parameters, i, form, params, key, input, formKey; + params = {}, parameters, i; for (i = 0; i < urlParams.length; i++) { parameters = urlParams[i].split('='); - paramData[decode(parameters[0])] = parameters[1] !== undefined ? + params[decode(parameters[0])] = parameters[1] !== undefined ? decode(parameters[1].replace(/\+/g, '%20')) : ''; } + + return params; + }, + + getCurrentLimit: function() + { + var currentLimit = this.getUrlParams()[this.options.limit]; + + if (currentLimit === undefined) { + currentLimit = this.options.limitDefault; + } + + return currentLimit; + }, + + + /** + * @param {String} paramName + * @param {*} paramValue + * @param {*} defaultValue + */ + changeUrl: function (paramName, paramValue, defaultValue) { + var urlPaths = this.options.url.split('?'), + baseUrl = urlPaths[0], + paramData = this.getUrlParams(), + form, params, key, input, formKey; + + if (paramName === this.options.limit && paramValue > this.getCurrentLimit()) { + delete paramData['p']; + } + paramData[paramName] = paramValue; if (this.options.post) { @@ -130,6 +154,7 @@ define([ if (paramValue == defaultValue) { //eslint-disable-line eqeqeq delete paramData[paramName]; } + paramData = $.param(paramData); location.href = baseUrl + (paramData.length ? '?' + paramData : ''); }