@nuskin/ns-product-lib 2.5.0-cx24-2467.3.1 → 2.5.0-cx24-2179.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +9 -2
- package/package.json +1 -1
- package/src/productData.js +61 -17
package/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
# [2.5.0-cx24-
|
1
|
+
# [2.5.0-cx24-2179.2.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.1...v2.5.0-cx24-2179.2.2) (2022-12-05)
|
2
|
+
|
3
|
+
|
4
|
+
### New
|
5
|
+
|
6
|
+
* added eq promotion support- debug sales event (#CX24-2179) ([992a2cf](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/992a2cfb178b3e12a6b8a0229ae5f6f607fb41d3)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
|
7
|
+
|
8
|
+
# [2.5.0-cx24-2179.2.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.2-CX24.2.1...v2.5.0-cx24-2179.2.1) (2022-12-02)
|
2
9
|
|
3
10
|
|
4
11
|
### Fix
|
@@ -7,7 +14,7 @@
|
|
7
14
|
|
8
15
|
### New
|
9
16
|
|
10
|
-
*
|
17
|
+
* added eq promotion support (#CX24-2179) ([bc7782d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bc7782dcc2b6db84bd4203ea64e60d80b55e4bcd)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
|
11
18
|
|
12
19
|
### Release
|
13
20
|
|
package/package.json
CHANGED
package/src/productData.js
CHANGED
@@ -91,7 +91,7 @@ const ProductData = {
|
|
91
91
|
|
92
92
|
/**
|
93
93
|
* Map product variant
|
94
|
-
* @todo remove unnecessary fields
|
94
|
+
* @todo remove unnecessary fields and do code refactoring
|
95
95
|
* @param {*} eqVariant
|
96
96
|
* @returns Array<Product>
|
97
97
|
*/
|
@@ -107,6 +107,10 @@ const ProductData = {
|
|
107
107
|
thumbnailImage = imageURL.replace(regex,'40.40')
|
108
108
|
}
|
109
109
|
|
110
|
+
const { eventName, eventLabels, computedPrice, defaultProductPrice} = this.getEqProductPromotions(eqVariant);
|
111
|
+
const productPrice = eventName ? defaultProductPrice : eqVariant.priceFacets["Regular Price"];
|
112
|
+
const wrtlPrice = eventName ? computedPrice : eqVariant.priceFacets["Regular Price"];
|
113
|
+
|
110
114
|
return {
|
111
115
|
"sku": eqVariant.identifier,
|
112
116
|
"globalProductID": eqVariant.identifier,
|
@@ -145,9 +149,9 @@ const ProductData = {
|
|
145
149
|
"cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
|
146
150
|
"pv":eqVariant.priceFacets.PV,
|
147
151
|
"priceType": "WRTL",
|
148
|
-
"price":
|
152
|
+
"price": productPrice,
|
149
153
|
"priceMap": {
|
150
|
-
"WRTL":
|
154
|
+
"WRTL": wrtlPrice,
|
151
155
|
"WADW-WRTL": eqVariant.priceFacets["Regular Price"],
|
152
156
|
"WADR": eqVariant.priceFacets["Regular Price"],
|
153
157
|
"RTL": eqVariant.priceFacets["Regular Price"],
|
@@ -181,9 +185,9 @@ const ProductData = {
|
|
181
185
|
"variantsLabel": eqVariant.properties.variantLabel || "",
|
182
186
|
"groupOffer": false,
|
183
187
|
"personalOffer": false,
|
184
|
-
"savedEventName":
|
185
|
-
"salesLabel":
|
186
|
-
"eventName":
|
188
|
+
"savedEventName": eventName,
|
189
|
+
"salesLabel": eventLabels,
|
190
|
+
"eventName": eventName,
|
187
191
|
"sizeWeight": '',
|
188
192
|
"nettoWeight": "",
|
189
193
|
"searchScore": 0,
|
@@ -198,6 +202,41 @@ const ProductData = {
|
|
198
202
|
};
|
199
203
|
},
|
200
204
|
|
205
|
+
/**
|
206
|
+
* Get EQ product promotions
|
207
|
+
* @param {*} product
|
208
|
+
* @returns {obj} promotion
|
209
|
+
*/
|
210
|
+
getEqProductPromotions(product) {
|
211
|
+
|
212
|
+
if (!Array.isArray(product.promotion)) {
|
213
|
+
return {
|
214
|
+
eventLabels: "",
|
215
|
+
computedPrice : 0,
|
216
|
+
defaultProductPrice: product.priceFacets ? product.priceFacets["Regular Price"] : 0,
|
217
|
+
eventName: null
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
const defaultProductPrice = product.totalValue ? product.totalValue.originalPrice : 0;
|
222
|
+
const computedPrice = product.totalValue && product.totalValue.priceAfterDiscount ? product.totalValue.priceAfterDiscount : 0;
|
223
|
+
let eventName = "";
|
224
|
+
const eventLabels = [];
|
225
|
+
|
226
|
+
product.promotion.map(promotion => {
|
227
|
+
eventName = promotion.offerId;
|
228
|
+
eventLabels.push(promotion.message);
|
229
|
+
return promotion;
|
230
|
+
});
|
231
|
+
|
232
|
+
return {
|
233
|
+
eventLabels: eventLabels.join(','),
|
234
|
+
defaultProductPrice,
|
235
|
+
computedPrice,
|
236
|
+
eventName
|
237
|
+
}
|
238
|
+
},
|
239
|
+
|
201
240
|
eqProductMapper: function (productDataResponse, skus) {
|
202
241
|
let prod = [];
|
203
242
|
let count = 0;
|
@@ -215,13 +254,17 @@ const ProductData = {
|
|
215
254
|
}
|
216
255
|
|
217
256
|
if (data.sku && data.sku.length > 1) {
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
257
|
+
//exclude base product from variants
|
258
|
+
data.sku.filter(v => v.identifier.substring(2, 4) !== "55").map(variant => {
|
259
|
+
variants[variant.identifier] = this.eqProductVariantMapper(variant);
|
260
|
+
return variant;
|
261
|
+
});
|
223
262
|
}
|
224
263
|
|
264
|
+
const { eventName, eventLabels, computedPrice, defaultProductPrice} = this.getEqProductPromotions(data.sku[count]);
|
265
|
+
const productPrice = eventName ? defaultProductPrice : data.sku[count].priceFacets["Regular Price"];
|
266
|
+
const wrtlPrice = eventName ? computedPrice : data.sku[count].priceFacets["Regular Price"];
|
267
|
+
|
225
268
|
prod = {
|
226
269
|
"sku": data.sku[count].identifier,
|
227
270
|
"globalProductID": data.identifier,
|
@@ -260,9 +303,9 @@ const ProductData = {
|
|
260
303
|
"cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
|
261
304
|
"pv": data.sku[count].priceFacets.PV,
|
262
305
|
"priceType": "WRTL",
|
263
|
-
"price":
|
306
|
+
"price": productPrice,
|
264
307
|
"priceMap": {
|
265
|
-
"WRTL":
|
308
|
+
"WRTL": wrtlPrice,
|
266
309
|
"WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
|
267
310
|
"WADR": data.sku[count].priceFacets["Regular Price"],
|
268
311
|
"RTL": data.sku[count].priceFacets["Regular Price"],
|
@@ -298,9 +341,9 @@ const ProductData = {
|
|
298
341
|
"variantsLabel": data.sku[count].properties.variantLabel || "",
|
299
342
|
"groupOffer": false,
|
300
343
|
"personalOffer": false,
|
301
|
-
"savedEventName":
|
302
|
-
"salesLabel":
|
303
|
-
"eventName":
|
344
|
+
"savedEventName": eventName,
|
345
|
+
"salesLabel": eventLabels,
|
346
|
+
"eventName": eventName,
|
304
347
|
"sizeWeight": '',
|
305
348
|
"nettoWeight": "",
|
306
349
|
"variants": variants,
|
@@ -318,8 +361,9 @@ const ProductData = {
|
|
318
361
|
};
|
319
362
|
let newProduct = new Product(prod);
|
320
363
|
return newProduct
|
321
|
-
})
|
364
|
+
});
|
322
365
|
|
366
|
+
console.log({context: "NsProductLib.eqProductMapper", product: prodArr});
|
323
367
|
let data = {
|
324
368
|
products: this._sortProductsBySku(skus, prodArr),
|
325
369
|
count: productDataResponse.length
|