@@ -23,6 +23,7 @@ define([
23
23
direction : 'product_list_dir' ,
24
24
order : 'product_list_order' ,
25
25
limit : 'product_list_limit' ,
26
+ page : 'p' ,
26
27
modeDefault : 'grid' ,
27
28
directionDefault : 'asc' ,
28
29
orderDefault : 'position' ,
@@ -80,7 +81,7 @@ define([
80
81
) ;
81
82
} ,
82
83
83
- getUrlParams : function ( ) {
84
+ getUrlParams : function ( ) {
84
85
var decode = window . decodeURIComponent ,
85
86
urlPaths = this . options . url . split ( '?' ) ,
86
87
urlParams = urlPaths [ 1 ] ? urlPaths [ 1 ] . split ( '&' ) : [ ] ,
@@ -96,17 +97,13 @@ define([
96
97
return params ;
97
98
} ,
98
99
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 ;
108
102
} ,
109
103
104
+ getCurrentPage : function ( ) {
105
+ return this . getUrlParams ( ) [ this . options . page ] || 1 ;
106
+ } ,
110
107
111
108
/**
112
109
* @param {String } paramName
@@ -117,10 +114,17 @@ define([
117
114
var urlPaths = this . options . url . split ( '?' ) ,
118
115
baseUrl = urlPaths [ 0 ] ,
119
116
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 ) ;
121
122
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
+ }
124
128
}
125
129
126
130
paramData [ paramName ] = paramValue ;
0 commit comments