/
final-price.js
289 lines (260 loc) · 8.12 KB
/
final-price.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'underscore',
'uiRegistry',
'mageUtils',
'uiCollection'
], function (_, registry, utils, Collection) {
'use strict';
return Collection.extend({
defaults: {
label: false,
headerTmpl: 'ui/grid/columns/text',
showMinimalPrice: false,
showMaximumPrice: false,
useLinkForAsLowAs: false,
bodyTmpl: 'Magento_Catalog/product/final_price',
priceWrapperCssClasses: '',
priceWrapperAttr: {}
},
/**
* Get product final price.
*
* @param {Object} row
* @return {HTMLElement} final price html
*/
getPrice: function (row) {
return row['price_info']['formatted_prices']['final_price'];
},
/**
* UnsanitizedHtml version of getPrice.
*
* @param {Object} row
* @return {HTMLElement} final price html
*/
getPriceUnsanitizedHtml: function (row) {
return this.getPrice(row);
},
/**
* Get product regular price.
*
* @param {Object} row
* @return {HTMLElement} regular price html
*/
getRegularPrice: function (row) {
return row['price_info']['formatted_prices']['regular_price'];
},
/**
* UnsanitizedHtml version of getRegularPrice.
*
* @param {Object} row
* @return {HTMLElement} regular price html
*/
getRegularPriceUnsanitizedHtml: function (row) {
return this.getRegularPrice(row);
},
/**
* Check if product has a price range.
*
* @param {Object} row
* @return {Boolean}
*/
hasPriceRange: function (row) {
return row['price_info']['max_regular_price'] !== row['price_info']['min_regular_price'];
},
/**
* Check if product has special price.
*
* @param {Object} row
* @return {HTMLElement} special price html
*/
hasSpecialPrice: function (row) {
return row['price_info']['regular_price'] > row['price_info']['final_price'];
},
/**
* Check if product has minimal price.
*
* @param {Object} row
* @return {HTMLElement} minimal price html
*/
isMinimalPrice: function (row) {
return row['price_info']['minimal_price'] < row['price_info']['final_price'];
},
/**
* Get product minimal price.
*
* @param {Object} row
* @return {HTMLElement} minimal price html
*/
getMinimalPrice: function (row) {
return row['price_info']['formatted_prices']['minimal_price'];
},
/**
* UnsanitizedHtml version of getMinimalPrice.
*
* @param {Object} row
* @return {HTMLElement} minimal price html
*/
getMinimalPriceUnsanitizedHtml: function (row) {
return this.getMinimalPrice(row);
},
/**
* Check if product is salable.
*
* @param {Object} row
* @return {Boolean}
*/
isSalable: function (row) {
return row['is_salable'];
},
/**
* Get product maximum price.
*
* @param {Object} row
* @return {HTMLElement} maximum price html
*/
getMaxPrice: function (row) {
return row['price_info']['formatted_prices']['max_price'];
},
/**
* UnsanitizedHtml version of getMaxPrice.
*
* @param {Object} row
* @return {HTMLElement} maximum price html
*/
getMaxPriceUnsanitizedHtml: function (row) {
return this.getMaxPrice(row);
},
/**
* Get product maximum regular price in case of price range and special price.
*
* @param {Object} row
* @return {HTMLElement} maximum regular price html
*/
getMaxRegularPrice: function (row) {
return row['price_info']['formatted_prices']['max_regular_price'];
},
/**
* UnsanitizedHtml version of getMaxRegularPrice.
*
* @param {Object} row
* @return {HTMLElement} maximum regular price html
*/
getMaxRegularPriceUnsanitizedHtml: function (row) {
return this.getMaxRegularPrice(row);
},
/**
* Get product minimal regular price in case of price range and special price.
*
* @param {Object} row
* @return {HTMLElement} minimal regular price html
*/
getMinRegularPrice: function (row) {
return row['price_info']['formatted_prices']['min_regular_price'];
},
/**
* UnsanitizedHtml version of getMinRegularPrice.
*
* @param {Object} row
* @return {HTMLElement} minimal regular price html
*/
getMinRegularPriceUnsanitizedHtml: function (row) {
return this.getMinRegularPrice(row);
},
/**
* Get adjustments names and return as string.
*
* @return {String} adjustments classes
*/
getAdjustmentCssClasses: function () {
return _.pluck(this.getAdjustments(), 'index').join(' ');
},
/**
* Get product minimal price as number.
*
* @param {Object} row
* @return {Number} minimal price amount
*/
getMinimalPriceAmount: function (row) {
return row['price_info']['minimal_price'];
},
/**
* UnsanitizedHtml version of getMinimalPriceAmount
*
* @param {Object} row
* @return {Number} minimal price amount
*/
getMinimalPriceAmountUnsanitizedHtml: function (row) {
return this.getMinimalPriceAmount(row);
},
/**
* Get product minimal regular price as number in case of special price.
*
* @param {Object} row
* @return {Number} minimal regular price amount
*/
getMinimalRegularPriceAmount: function (row) {
return row['price_info']['min_regular_price'];
},
/**
* Get product maximum price as number.
*
* @param {Object} row
* @return {Number} maximum price amount
*/
getMaximumPriceAmount: function (row) {
return row['price_info']['max_price'];
},
/**
* Get product maximum regular price as number in case of special price.
*
* @param {Object} row
* @return {Number} maximum regular price amount
*/
getMaximumRegularPriceAmount: function (row) {
return row['price_info']['max_regular_price'];
},
/**
* Check if minimal regular price exist for product.
*
* @param {Object} row
* @return {Boolean}
*/
showMinRegularPrice: function (row) {
return this.getMinimalPriceAmount(row) < this.getMinimalRegularPriceAmount(row);
},
/**
* Check if maximum regular price exist for product.
*
* @param {Object} row
* @return {Boolean}
*/
showMaxRegularPrice: function (row) {
return this.getMaximumPriceAmount(row) < this.getMaximumRegularPriceAmount(row);
},
/**
* Get path to the columns' body template.
*
* @returns {String}
*/
getBody: function () {
return this.bodyTmpl;
},
/**
* Get all price adjustments.
*
* @returns {Object}
*/
getAdjustments: function () {
var adjustments = this.elems();
_.each(adjustments, function (adjustment) {
adjustment.setPriceType(this.priceType);
adjustment.source = this.source;
}, this);
return adjustments;
}
});
});