@nuskin/ns-product-lib 2.5.0-cx24-2179.1 → 2.5.0-cx24-2179.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +2 -2
- package/package.json +1 -1
- package/src/productData.js +172 -54
package/CHANGELOG.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [2.5.0-cx24-2179.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.1) (2022-
|
1
|
+
# [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
2
|
|
3
3
|
|
4
4
|
### Fix
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
### New
|
9
9
|
|
10
|
-
* added
|
10
|
+
* 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
11
|
|
12
12
|
### Release
|
13
13
|
|
package/package.json
CHANGED
package/src/productData.js
CHANGED
@@ -90,12 +90,13 @@ const ProductData = {
|
|
90
90
|
},
|
91
91
|
|
92
92
|
/**
|
93
|
-
*
|
94
|
-
* @todo remove unnecessary fields
|
93
|
+
* Map product variant
|
94
|
+
* @todo remove unnecessary fields and do code refactoring
|
95
95
|
* @param {*} eqVariant
|
96
|
-
* @returns
|
96
|
+
* @returns Array<Product>
|
97
97
|
*/
|
98
|
-
|
98
|
+
eqProductVariantMapper : function (eqVariant) {
|
99
|
+
|
99
100
|
let imageURL = eqVariant.properties.imageURL;
|
100
101
|
const regex = /\d+.\d+/
|
101
102
|
let thumbnailImage = ''
|
@@ -106,10 +107,11 @@ const ProductData = {
|
|
106
107
|
thumbnailImage = imageURL.replace(regex,'40.40')
|
107
108
|
}
|
108
109
|
|
109
|
-
|
110
|
-
const
|
111
|
-
const
|
112
|
-
|
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
|
+
|
114
|
+
return {
|
113
115
|
"sku": eqVariant.identifier,
|
114
116
|
"globalProductID": eqVariant.identifier,
|
115
117
|
"title": eqVariant.properties.name,
|
@@ -144,28 +146,28 @@ const ProductData = {
|
|
144
146
|
"availableQuantity": eqVariant.inventoryProperties.atpQty,
|
145
147
|
"maxQuantity": 999,
|
146
148
|
"points": "",
|
147
|
-
"cv": eqVariant.priceFacets ? eqVariant.priceFacets.CV : '',
|
148
|
-
"pv":
|
149
|
+
"cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
|
150
|
+
"pv":eqVariant.priceFacets.PV,
|
149
151
|
"priceType": "WRTL",
|
150
152
|
"price": productPrice,
|
151
153
|
"priceMap": {
|
152
|
-
"WRTL":
|
153
|
-
"WADW-WRTL":
|
154
|
-
"WADR": eqVariant.
|
155
|
-
"RTL": eqVariant.
|
156
|
-
"WWHL": eqVariant.
|
157
|
-
"WADW": eqVariant.
|
158
|
-
"WHL": eqVariant.
|
154
|
+
"WRTL": wrtlPrice,
|
155
|
+
"WADW-WRTL": eqVariant.priceFacets["Regular Price"],
|
156
|
+
"WADR": eqVariant.priceFacets["Regular Price"],
|
157
|
+
"RTL": eqVariant.priceFacets["Regular Price"],
|
158
|
+
"WWHL": eqVariant.priceFacets["Wholesale Price"],
|
159
|
+
"WADW": eqVariant.priceFacets["Wholesale Price"],
|
160
|
+
"WHL": eqVariant.priceFacets["Wholesale Price"]
|
159
161
|
},
|
160
162
|
"cvMap": {
|
161
|
-
"WWHL": (eqVariant.priceFacets) ? eqVariant.priceFacets.CV : '',
|
162
|
-
"WADW": (eqVariant.priceFacets) ? eqVariant.priceFacets.CV : '',
|
163
|
-
"WHL": (eqVariant.priceFacets) ? eqVariant.priceFacets.CV : ''
|
163
|
+
"WWHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
|
164
|
+
"WADW": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
|
165
|
+
"WHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : ''
|
164
166
|
},
|
165
167
|
"pvMap": {
|
166
|
-
"WWHL":
|
167
|
-
"WADW": eqVariant.priceFacets
|
168
|
-
"WHL": eqVariant.priceFacets
|
168
|
+
"WWHL": eqVariant.priceFacets.PV,
|
169
|
+
"WADW": eqVariant.priceFacets.PV,
|
170
|
+
"WHL": eqVariant.priceFacets.PV
|
169
171
|
},
|
170
172
|
"orderTypes": this._setOrderType(eqVariant.properties),
|
171
173
|
"division": eqVariant.properties.division,
|
@@ -183,9 +185,9 @@ const ProductData = {
|
|
183
185
|
"variantsLabel": eqVariant.properties.variantLabel || "",
|
184
186
|
"groupOffer": false,
|
185
187
|
"personalOffer": false,
|
186
|
-
"savedEventName":
|
187
|
-
"salesLabel":
|
188
|
-
"eventName":
|
188
|
+
"savedEventName": eventName,
|
189
|
+
"salesLabel": eventLabels,
|
190
|
+
"eventName": eventName,
|
189
191
|
"sizeWeight": '',
|
190
192
|
"nettoWeight": "",
|
191
193
|
"searchScore": 0,
|
@@ -198,57 +200,173 @@ const ProductData = {
|
|
198
200
|
"restrictedMarkets": [],
|
199
201
|
"addOns": []
|
200
202
|
};
|
201
|
-
|
202
203
|
},
|
203
204
|
|
204
|
-
|
205
205
|
/**
|
206
|
-
*
|
207
|
-
*
|
208
|
-
* @
|
209
|
-
* @returns Array<Product>
|
206
|
+
* Get EQ product promotions
|
207
|
+
* @param {*} product
|
208
|
+
* @returns {obj} promotion
|
210
209
|
*/
|
211
|
-
|
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
|
+
}
|
212
220
|
|
213
|
-
|
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 = [];
|
214
225
|
|
215
|
-
|
216
|
-
|
217
|
-
|
226
|
+
product.promotion.map(promotion => {
|
227
|
+
eventName = promotion.offerId;
|
228
|
+
eventLabels.push(promotion.message);
|
229
|
+
return promotion;
|
218
230
|
});
|
219
231
|
|
220
|
-
return
|
232
|
+
return {
|
233
|
+
eventLabels: eventLabels.join(','),
|
234
|
+
defaultProductPrice,
|
235
|
+
computedPrice,
|
236
|
+
eventName
|
237
|
+
}
|
221
238
|
},
|
222
239
|
|
223
|
-
|
224
|
-
/**
|
225
|
-
* eqProductMapper
|
226
|
-
* @param {*} productDataResponse
|
227
|
-
* @param {*} skus
|
228
|
-
* @returns obj
|
229
|
-
*/
|
230
240
|
eqProductMapper: function (productDataResponse, skus) {
|
241
|
+
let prod = [];
|
231
242
|
let count = 0;
|
232
243
|
let variants = {};
|
233
244
|
|
234
245
|
let prodArr = productDataResponse.map((data) => {
|
246
|
+
let imageURL = data.sku[count].properties.imageURL;
|
247
|
+
const regex = /\d+.\d+/
|
248
|
+
let thumbnailImage = ''
|
249
|
+
|
250
|
+
if (imageURL.includes('contentstack')) {
|
251
|
+
thumbnailImage = imageURL + '?width=40'
|
252
|
+
} else {
|
253
|
+
thumbnailImage = imageURL.replace(regex,'40.40')
|
254
|
+
}
|
235
255
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
256
|
+
if (data.sku && data.sku.length > 1) {
|
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
|
+
});
|
240
262
|
}
|
241
263
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
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
|
+
|
268
|
+
prod = {
|
269
|
+
"sku": data.sku[count].identifier,
|
270
|
+
"globalProductID": data.identifier,
|
271
|
+
"title": data.properties.name,
|
272
|
+
"country": data.sku[count].properties.market,
|
273
|
+
"language": "en",
|
274
|
+
"shortDescr": data.properties.description,
|
275
|
+
"longDescr": data.properties.productDetailsDescription,
|
276
|
+
"fullImage": imageURL,
|
277
|
+
"imageAltText": data.properties.name,
|
278
|
+
"productCarouselImages": [
|
279
|
+
{
|
280
|
+
"contentType": "img",
|
281
|
+
"src": "/content/products/24/00/35/24003529/jcr:content/fullImage.imgw.1280.1280.png",
|
282
|
+
"alt": ""
|
283
|
+
}
|
284
|
+
],
|
285
|
+
"thumbnail": thumbnailImage,
|
286
|
+
"ingredients": data.properties.ingredients,
|
287
|
+
"benefits": data.properties.benefits,
|
288
|
+
"usage": data.properties.usage,
|
289
|
+
"resources": data.sku[count].properties.resources,
|
290
|
+
"videos": "",
|
291
|
+
"movie": "",
|
292
|
+
"youtube": "",
|
293
|
+
"salesEventText": "",
|
294
|
+
"contentSection": [
|
295
|
+
{
|
296
|
+
"sectionContent": "<div class=\"contentSections\"></div>\n"
|
297
|
+
}
|
298
|
+
],
|
299
|
+
"scanQualified": data.properties.scanQualifiedCount,
|
300
|
+
"availableQuantity": data.sku[count].inventoryProperties.atpQty,
|
301
|
+
"maxQuantity": 999,
|
302
|
+
"points": "",
|
303
|
+
"cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
|
304
|
+
"pv": data.sku[count].priceFacets.PV,
|
305
|
+
"priceType": "WRTL",
|
306
|
+
"price": productPrice,
|
307
|
+
"priceMap": {
|
308
|
+
"WRTL": wrtlPrice,
|
309
|
+
"WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
|
310
|
+
"WADR": data.sku[count].priceFacets["Regular Price"],
|
311
|
+
"RTL": data.sku[count].priceFacets["Regular Price"],
|
312
|
+
"WADW": data.sku[count].priceFacets["Wholesale Price"],
|
313
|
+
"WHL": data.sku[count].priceFacets["Wholesale Price"],
|
314
|
+
"WWHL": data.sku[count].priceFacets["Wholesale Price"]
|
315
|
+
},
|
316
|
+
"cvMap": {
|
317
|
+
"WWHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
|
318
|
+
"WADW": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
|
319
|
+
"WHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : ''
|
320
|
+
},
|
321
|
+
"pvMap": {
|
322
|
+
"WWHL": data.sku[count].priceFacets.PV,
|
323
|
+
"WADW": data.sku[count].priceFacets.PV,
|
324
|
+
"WHL": data.sku[count].priceFacets.PV
|
325
|
+
},
|
326
|
+
"orderTypes": this._setOrderType(data.sku[count].properties),
|
327
|
+
"childSkus": [],
|
328
|
+
"custTypes": this.switchCustType(data.properties.customerTypes),
|
329
|
+
"division": data.properties.division,
|
330
|
+
"backOrderDate": null,
|
331
|
+
"locallyProduced": false,
|
332
|
+
"agelocme": null,
|
333
|
+
"count": "",
|
334
|
+
"flavor": "",
|
335
|
+
"size": data.sku[count].properties.size,
|
336
|
+
"shade": "",
|
337
|
+
"status": this.switchStatusFromEquinox(data.sku[count].properties.productStatus),
|
338
|
+
"variantType": "Other",
|
339
|
+
"variantDropdownLabel": data.sku[count].properties.variantLabel || "",
|
340
|
+
"variantDropdownPlaceholder": "Select Type",
|
341
|
+
"variantsLabel": data.sku[count].properties.variantLabel || "",
|
342
|
+
"groupOffer": false,
|
343
|
+
"personalOffer": false,
|
344
|
+
"savedEventName": eventName,
|
345
|
+
"salesLabel": eventLabels,
|
346
|
+
"eventName": eventName,
|
347
|
+
"sizeWeight": '',
|
348
|
+
"nettoWeight": "",
|
349
|
+
"variants": variants,
|
350
|
+
"searchScore": 0,
|
351
|
+
"isExclusive": data.sku[count].properties.isExclusive,
|
352
|
+
"marketAttributes": {
|
353
|
+
"discount": true,
|
354
|
+
"redeem": true,
|
355
|
+
"earn": true
|
356
|
+
},
|
357
|
+
"restrictedMarkets": [],
|
358
|
+
"addOns": [],
|
359
|
+
"inventory": data.sku[count].inventory || "" //inventory label
|
360
|
+
|
361
|
+
};
|
362
|
+
let newProduct = new Product(prod);
|
363
|
+
return newProduct
|
364
|
+
})
|
246
365
|
|
247
366
|
let data = {
|
248
367
|
products: this._sortProductsBySku(skus, prodArr),
|
249
368
|
count: productDataResponse.length
|
250
369
|
};
|
251
|
-
|
252
370
|
return {
|
253
371
|
data: {
|
254
372
|
"status": 200,
|