@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 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-11-21)
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 support for variant and promotion (#CX24-2179) ([cf1f623](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/cf1f623c61de55fb969e7debd5c456483f1283b5)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.5.0-cx24-2179.1",
3
+ "version": "2.5.0-cx24-2179.2.1",
4
4
  "description": "This project contains shared Product models and code between the backend and frontend.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -90,12 +90,13 @@ const ProductData = {
90
90
  },
91
91
 
92
92
  /**
93
- * map product from equinox to nuskin product data structure
94
- * @todo remove unnecessary fields
93
+ * Map product variant
94
+ * @todo remove unnecessary fields and do code refactoring
95
95
  * @param {*} eqVariant
96
- * @returns obj Product
96
+ * @returns Array<Product>
97
97
  */
98
- productMapper : function(eqVariant) {
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
- //get the last promotion
110
- const salesPromotion = Array.isArray(eqVariant.promotion) > 0 ? eqVariant.promotion[eqVariant.promotion.length - 1] : null;
111
- const productPrice = salesPromotion && salesPromotion.discount ? salesPromotion.discount : (eqVariant.priceFacet ? eqVariant.priceFacets["Regular Price"] : '');
112
- return {
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": eqVariant.priceFacets ? eqVariant.priceFacets.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": productPrice,
153
- "WADW-WRTL": productPrice,
154
- "WADR": eqVariant.priceFacet ? eqVariant.priceFacets["Regular Price"] : '',
155
- "RTL": eqVariant.priceFacet ? eqVariant.priceFacets["Regular Price"] : '',
156
- "WWHL": eqVariant.priceFacet ? eqVariant.priceFacets["Wholesale Price"] : '',
157
- "WADW": eqVariant.priceFacet ? eqVariant.priceFacets["Wholesale Price"] : '',
158
- "WHL": eqVariant.priceFacet ? eqVariant.priceFacets["Wholesale Price"] : ''
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": eqVariant.priceFacets ? eqVariant.priceFacets.PV : '',
167
- "WADW": eqVariant.priceFacets ? eqVariant.priceFacets.PV : '',
168
- "WHL": eqVariant.priceFacets ? eqVariant.priceFacets.PV : ''
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": salesPromotion ? salesPromotion.promotionClass : '',
187
- "salesLabel": salesPromotion ? salesPromotion.message : '',
188
- "eventName": salesPromotion ? salesPromotion.promotionClass : '',
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
- * Map product variants
208
- * @param Array<eqVariant>
209
- * @returns Array<Product>
206
+ * Get EQ product promotions
207
+ * @param {*} product
208
+ * @returns {obj} promotion
210
209
  */
211
- eqProductVariantMapper : function (eqVariants) {
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
- let variants = {};
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
- eqVariants.map(eqVariant => {
216
- variants[eqVariant.identifier] = this.productMapper(eqVariant);
217
- return eqVariant;
226
+ product.promotion.map(promotion => {
227
+ eventName = promotion.offerId;
228
+ eventLabels.push(promotion.message);
229
+ return promotion;
218
230
  });
219
231
 
220
- return variants;
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
- const mappedProduct = this.productMapper(data.sku[count]);
237
-
238
- if (data.sku && data.sku.length > 0) {
239
- variants = this.eqProductVariantMapper(data.sku);
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
- let newProduct = new Product({...mappedProduct, variants: variants});
243
- return newProduct;
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,