Skip to content

Commit f25de7b

Browse files
committed
Introduce redirect pattern during change of limit
1 parent 05f1a2b commit f25de7b

File tree

1 file changed

+17
-13
lines changed
  • app/code/Magento/Catalog/view/frontend/web/js/product/list

1 file changed

+17
-13
lines changed

app/code/Magento/Catalog/view/frontend/web/js/product/list/toolbar.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ define([
2323
direction: 'product_list_dir',
2424
order: 'product_list_order',
2525
limit: 'product_list_limit',
26+
page: 'p',
2627
modeDefault: 'grid',
2728
directionDefault: 'asc',
2829
orderDefault: 'position',
@@ -80,7 +81,7 @@ define([
8081
);
8182
},
8283

83-
getUrlParams: function() {
84+
getUrlParams: function () {
8485
var decode = window.decodeURIComponent,
8586
urlPaths = this.options.url.split('?'),
8687
urlParams = urlPaths[1] ? urlPaths[1].split('&') : [],
@@ -96,17 +97,13 @@ define([
9697
return params;
9798
},
9899

99-
getCurrentLimit: function()
100-
{
101-
var currentLimit = this.getUrlParams()[this.options.limit];
102-
103-
if (currentLimit === undefined) {
104-
currentLimit = this.options.limitDefault;
105-
}
106-
107-
return currentLimit;
100+
getCurrentLimit: function () {
101+
return this.getUrlParams()[this.options.limit] || this.options.limitDefault;
108102
},
109103

104+
getCurrentPage: function () {
105+
return this.getUrlParams()[this.options.page] || 1;
106+
},
110107

111108
/**
112109
* @param {String} paramName
@@ -117,10 +114,17 @@ define([
117114
var urlPaths = this.options.url.split('?'),
118115
baseUrl = urlPaths[0],
119116
paramData = this.getUrlParams(),
120-
form, params, key, input, formKey;
117+
currentPage = this.getCurrentPage(),
118+
form, params, key, input, formKey, newPage;
119+
120+
if (currentPage > 1 && paramName === this.options.limit) {
121+
newPage = Math.floor(this.getCurrentLimit() * this.getCurrentPage() / paramValue);
121122

122-
if (paramName === this.options.limit && paramValue > this.getCurrentLimit()) {
123-
delete paramData['p'];
123+
if (newPage > 1) {
124+
paramData[this.options.page] = newPage;
125+
} else {
126+
delete paramData[this.options.page];
127+
}
124128
}
125129

126130
paramData[paramName] = paramValue;

0 commit comments

Comments
 (0)