8
8
'jquery' ,
9
9
'ko' ,
10
10
'underscore' ,
11
+ 'Magento_Ui/js/grid/paging/paging' ,
11
12
'mage/translate'
12
- ] , function ( Component , $ , ko , _ ) {
13
+ ] , function ( Component , $ , ko , _ , paging ) {
13
14
'use strict' ;
14
15
15
16
return Component . extend ( {
@@ -25,31 +26,70 @@ define([
25
26
gridExisting : [ ] ,
26
27
gridNew : [ ] ,
27
28
gridDeleted : [ ] ,
29
+ variationsExisting : [ ] ,
30
+ variationsNew : [ ] ,
31
+ variationsDeleted : [ ] ,
32
+ pagingExisting : paging ( {
33
+ name : 'configurableWizard.pagingExisting' ,
34
+ sizesConfig : {
35
+ component : 'Magento_ConfigurableProduct/js/variations/paging/sizes' ,
36
+ name : 'configurableWizard.pagingExisting_sizes'
37
+ }
38
+ } ) ,
39
+ pagingNew : paging ( {
40
+ name : 'configurableWizard.pagingNew' ,
41
+ sizesConfig : {
42
+ component : 'Magento_ConfigurableProduct/js/variations/paging/sizes' ,
43
+ name : 'configurableWizard.pagingNew_sizes'
44
+ }
45
+ } ) ,
46
+ pagingDeleted : paging ( {
47
+ name : 'configurableWizard.pagingDeleted' ,
48
+ sizesConfig : {
49
+ component : 'Magento_ConfigurableProduct/js/variations/paging/sizes' ,
50
+ name : 'configurableWizard.pagingDeleted_sizes'
51
+ }
52
+ } ) ,
28
53
attributes : [ ] ,
29
54
attributesName : [ $ . mage . __ ( 'Images' ) , $ . mage . __ ( 'SKU' ) , $ . mage . __ ( 'Quantity' ) , $ . mage . __ ( 'Price' ) ] ,
30
55
sections : [ ] ,
31
56
gridTemplate : 'Magento_ConfigurableProduct/variations/steps/summary-grid'
32
57
} ,
33
58
initObservable : function ( ) {
59
+ var pagingObservables = {
60
+ currentNew : ko . getObservable ( this . pagingNew , 'current' ) ,
61
+ currentExisting : ko . getObservable ( this . pagingExisting , 'current' ) ,
62
+ currentDeleted : ko . getObservable ( this . pagingDeleted , 'current' ) ,
63
+ pageSizeNew : ko . getObservable ( this . pagingNew , 'pageSize' ) ,
64
+ pageSizeExisting : ko . getObservable ( this . pagingExisting , 'pageSize' ) ,
65
+ pageSizeDeleted : ko . getObservable ( this . pagingDeleted , 'pageSize' )
66
+ } ;
67
+
34
68
this . _super ( ) . observe ( 'gridExisting gridNew gridDeleted attributes sections' ) ;
35
69
this . gridExisting . columns = ko . observableArray ( ) ;
36
70
this . gridNew . columns = ko . observableArray ( ) ;
37
71
this . gridDeleted . columns = ko . observableArray ( ) ;
38
72
73
+ _ . each ( pagingObservables , function ( observable ) {
74
+ observable . subscribe ( function ( ) {
75
+ this . generateGrid ( ) ;
76
+ } , this ) ;
77
+ } , this ) ;
78
+
39
79
return this ;
40
80
} ,
41
81
nextLabelText : $ . mage . __ ( 'Generate Products' ) ,
42
82
variations : [ ] ,
43
- generateGrid : function ( variations , getSectionValue ) {
83
+ calculate : function ( variations , getSectionValue ) {
44
84
var productSku = this . variationsComponent ( ) . getProductValue ( 'sku' ) ,
45
85
productPrice = this . variationsComponent ( ) . getProductPrice ( ) ,
46
86
productWeight = this . variationsComponent ( ) . getProductValue ( 'weight' ) ,
47
87
variationsKeys = [ ] ,
48
88
gridExisting = [ ] ,
49
89
gridNew = [ ] ,
50
90
gridDeleted = [ ] ;
51
- this . variations = [ ] ;
52
91
92
+ this . variations = [ ] ;
53
93
_ . each ( variations , function ( options ) {
54
94
var product , images , sku , quantity , price , variation ,
55
95
productId = this . variationsComponent ( ) . getProductIdByOptions ( options ) ;
@@ -101,14 +141,6 @@ define([
101
141
variationsKeys . push ( this . variationsComponent ( ) . getVariationKey ( options ) ) ;
102
142
} , this ) ;
103
143
104
- this . gridExisting ( gridExisting ) ;
105
- this . gridExisting . columns ( this . getColumnsName ( this . wizard . data . attributes ) ) ;
106
-
107
- if ( gridNew . length > 0 ) {
108
- this . gridNew ( gridNew ) ;
109
- this . gridNew . columns ( this . getColumnsName ( this . wizard . data . attributes ) ) ;
110
- }
111
-
112
144
_ . each ( _ . omit ( this . variationsComponent ( ) . productAttributesMap , variationsKeys ) , function ( productId ) {
113
145
gridDeleted . push ( this . prepareRowForGrid (
114
146
_ . findWhere ( this . variationsComponent ( ) . variations , {
@@ -117,13 +149,28 @@ define([
117
149
) ) ;
118
150
} . bind ( this ) ) ;
119
151
120
- if ( gridDeleted . length > 0 ) {
121
- this . gridDeleted ( gridDeleted ) ;
122
- this . gridDeleted . columns ( this . getColumnsName ( this . variationsComponent ( ) . productAttributes ) ) ;
123
- }
152
+ this . variationsExisting = gridExisting ;
153
+ this . variationsNew = gridNew ;
154
+ this . variationsDeleted = gridDeleted ;
155
+
156
+ } ,
157
+ generateGrid : function ( ) {
158
+ var pageExisting = this . pagingExisting . pageSize * this . pagingExisting . current ,
159
+ pageNew = this . pagingNew . pageSize * this . pagingNew . current ,
160
+ pageDeleted = this . pagingDeleted . pageSize * this . pagingDeleted . current ;
161
+
162
+ this . pagingExisting . totalRecords = this . variationsExisting . length ;
163
+ this . gridExisting ( this . variationsExisting . slice ( pageExisting - this . pagingExisting . pageSize , pageExisting ) ) ;
164
+
165
+ this . pagingNew . totalRecords = this . variationsNew . length ;
166
+ this . gridNew ( this . variationsNew . slice ( pageNew - this . pagingNew . pageSize , pageNew ) ) ;
167
+
168
+ this . pagingDeleted . totalRecords = this . variationsDeleted . length ;
169
+ this . gridDeleted ( this . variationsDeleted . slice ( pageDeleted - this . pagingDeleted . pageSize , pageDeleted ) ) ;
124
170
} ,
125
171
prepareRowForGrid : function ( variation ) {
126
172
var row = [ ] ;
173
+
127
174
row . push ( _ . extend ( {
128
175
images : [ ]
129
176
} , variation . images ) ) ;
@@ -158,7 +205,11 @@ define([
158
205
this . gridNew ( [ ] ) ;
159
206
this . gridExisting ( [ ] ) ;
160
207
this . gridDeleted ( [ ] ) ;
161
- this . generateGrid ( wizard . data . variations , wizard . data . sectionHelper ) ;
208
+ this . gridExisting . columns ( this . getColumnsName ( this . wizard . data . attributes ) ) ;
209
+ this . gridNew . columns ( this . getColumnsName ( this . wizard . data . attributes ) ) ;
210
+ this . gridDeleted . columns ( this . getColumnsName ( this . variationsComponent ( ) . productAttributes ) ) ;
211
+ this . calculate ( wizard . data . variations , wizard . data . sectionHelper ) ;
212
+ this . generateGrid ( ) ;
162
213
} ,
163
214
force : function ( ) {
164
215
this . variationsComponent ( ) . render ( this . variations , this . attributes ( ) ) ;
0 commit comments