@nuskin/ns-product-lib 2.4.2-CX24.2.1 → 2.5.0-CX24.3.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,9 +1,45 @@
1
- ## [2.4.2-CX24.2.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.1...v2.4.2-CX24.2.1) (2022-11-07)
1
+ # [2.5.0-CX24.3.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.3.1) (2022-12-06)
2
2
 
3
3
 
4
4
  ### Fix
5
5
 
6
- * [Equinox market] Admin > Move up/down/top/bottom of featured products and edit bundle is not working ([82611ca](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/82611cab93c990ed1ce05690feb9d00967090dea))
6
+ * [Equinox market] Admin > Move up/down/top/bottom of featured products and edit bundle is not working ([a89af4a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/a89af4a5d00c6a68fcaeff22f128554270add21e))
7
+ * eq market event pricing and name (#CX24-2179) ([213b59a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/213b59a33a208ffad0a6726521ce7f365d34d36e)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
8
+
9
+ ### Release
10
+
11
+ * Automated changes by GitLab pipeline [skip ci] ([07bfa40](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/07bfa404c552c05637c2c8a537c4ff298536874e))
12
+ * Automated changes by GitLab pipeline [skip ci] ([fa1c0d9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/fa1c0d9d5853482e3ac49cea4e99599e7192f85b))
13
+ * Automated changes by GitLab pipeline [skip ci] ([2d20787](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/2d2078763b2d57edb8a24f438ac90dd37c3ff41b))
14
+
15
+ ### Update
16
+
17
+ * set ADR pricing from equinox (CX24-2862) ([65d04d2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/65d04d2e9ff4018edfe99e5a7412bee985d3def2))
18
+ * set ADR pricing from equinox (CX24-2862) ([54a5693](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/54a56932e5df36c9c30ce6358d8597c98be3d20d))
19
+ * set ADR pricing from equinox (CX24-2862) ([bbd135f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bbd135f1ed0395c578be2274c84ba136ceed9376))
20
+ * set ADR pricing from equinox (CX24-2862) ([197003e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/197003e1629bd394c547a118d332b5e8574dfc7d))
21
+
22
+ # [2.5.0-cx24-2862.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2862.1...v2.5.0-cx24-2862.2) (2022-11-11)
23
+
24
+
25
+ ### Update
26
+
27
+ * set ADR pricing from equinox (CX24-2862) ([b64dcea](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b64dcea4dd3374be992c667db5c0b2604aacc029))
28
+
29
+ # [2.5.0-cx24-2862.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.2-cx24-2612.1.1...v2.5.0-cx24-2862.1) (2022-11-10)
30
+
31
+
32
+ ### Update
33
+
34
+ * set ADR pricing from equinox (CX24-2862) ([9f6dfb7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9f6dfb726f40b1335411318629a2ebdf1b4dac96))
35
+ * set ADR pricing from equinox (CX24-2862) ([61f550a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/61f550a21c5cc9d062549ec2aaf2758aebccf2be))
36
+
37
+ ## [2.4.2-cx24-2612.1.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.1...v2.4.2-cx24-2612.1.1) (2022-11-07)
38
+
39
+
40
+ ### Fix
41
+
42
+ * [Equinox market] Admin > Move up/down/top/bottom of featured products and edit bundle is not working ([9d9d106](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9d9d10667477b4c7ef7bf8ec013aab322d3cdbcc))
7
43
 
8
44
  ## [2.4.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.0...v2.4.1) (2022-11-06)
9
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.4.2-CX24.2.1",
3
+ "version": "2.5.0-CX24.3.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": {
package/src/product.js CHANGED
@@ -225,7 +225,7 @@ const Product = function(productData) {
225
225
  }
226
226
  };
227
227
 
228
- this.setPriceAndPvFromType = function(_priceType, _activeEvents = null) {
228
+ this.setPriceAndPvFromType = function(_priceType, _activeEvents = null, option = {}) {
229
229
  // WARNING: priceType needs to be handled client-side
230
230
  // const priceType = ConfigService.getMarketConfig().showWholeSalePricing && !AccountManager.isLoggedIn()
231
231
  // ? PriceType.WWHL
@@ -234,11 +234,11 @@ const Product = function(productData) {
234
234
  const eventPricing = getEventPricing(this, priceType, _activeEvents);
235
235
 
236
236
  let changed = false;
237
- if (
237
+ if ((
238
238
  !this.price ||
239
239
  priceType !== this.priceType ||
240
240
  this.eventName !== eventPricing.eventName
241
- ) {
241
+ ) && !option.isEqPromotion) {
242
242
  this.setPrice(eventPricing.price || this.getPricing(priceType));
243
243
  this.setCv(eventPricing.cv || this.getCvWithType(priceType));
244
244
  this.setPv(eventPricing.pv || this.getPvWithType(priceType));
@@ -247,11 +247,20 @@ const Product = function(productData) {
247
247
  changed = true;
248
248
  }
249
249
 
250
+ if (option.isEqPromotion) {
251
+ //retain product.price as original price
252
+ this.setCv(this.getCvWithType(priceType));
253
+ this.setPv(this.getPvWithType(priceType));
254
+ this.priceType = priceType;
255
+ changed = true;
256
+ }
257
+
250
258
  this.variantSkus().forEach((variantSku) => {
251
259
  if (
252
260
  this.variants[variantSku].setPriceAndPvFromType(
253
261
  priceType,
254
- _activeEvents
262
+ _activeEvents,
263
+ option
255
264
  )
256
265
  ) {
257
266
  changed = true;
@@ -281,7 +290,7 @@ const Product = function(productData) {
281
290
  this.priceMap[type] = price;
282
291
  };
283
292
 
284
- this.addPricingFromStatus = function(productStatus, priceType) {
293
+ this.addPricingFromStatus = function(productStatus, priceType, option ={}) {
285
294
  let modified = false;
286
295
 
287
296
  if (!priceType) {
@@ -319,13 +328,13 @@ const Product = function(productData) {
319
328
  if(productStatus.childSkus) {
320
329
  this.childSkus = productStatus.childSkus;
321
330
  }
322
- this.setPriceAndPvFromType(priceType);
331
+ this.setPriceAndPvFromType(priceType, null, option);
323
332
  modified = true;
324
333
  } else {
325
334
  let variant = this.getVariant(productStatusSku);
326
335
 
327
336
  if (variant) {
328
- if (variant.addPricingFromStatus(productStatus, priceType)) {
337
+ if (variant.addPricingFromStatus(productStatus, priceType, option)) {
329
338
  variant.setMarketAttributes(productStatus);
330
339
  updateBaseRanges(this, variant);
331
340
  modified = true;
@@ -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 discountedPrice = eventName ? computedPrice : eqVariant.priceFacets["Regular Price"];
113
+
110
114
  return {
111
115
  "sku": eqVariant.identifier,
112
116
  "globalProductID": eqVariant.identifier,
@@ -145,14 +149,14 @@ const ProductData = {
145
149
  "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
146
150
  "pv":eqVariant.priceFacets.PV,
147
151
  "priceType": "WRTL",
148
- "price": eqVariant.priceFacets["Regular Price"],
152
+ "price": discountedPrice,
149
153
  "priceMap": {
150
- "WRTL": eqVariant.priceFacets["Regular Price"],
154
+ "WRTL": productPrice,
151
155
  "WADW-WRTL": eqVariant.priceFacets["Regular Price"],
152
- "WADR": 9999.01,
156
+ "WADR": eqVariant.priceFacets["Regular Price"],
153
157
  "RTL": eqVariant.priceFacets["Regular Price"],
154
158
  "WWHL": eqVariant.priceFacets["Wholesale Price"],
155
- "WADW": 9998.01,
159
+ "WADW": eqVariant.priceFacets["Wholesale Price"],
156
160
  "WHL": eqVariant.priceFacets["Wholesale Price"]
157
161
  },
158
162
  "cvMap": {
@@ -165,19 +169,7 @@ const ProductData = {
165
169
  "WADW": eqVariant.priceFacets.PV,
166
170
  "WHL": eqVariant.priceFacets.PV
167
171
  },
168
- "orderTypes": {
169
- "adr": true,
170
- "order": true,
171
- "zpfc": false,
172
- "zadp": true,
173
- "ars": true,
174
- "kiosk": true,
175
- "mobile": true,
176
- "preferred customer": true,
177
- "retail": true,
178
- "web": true,
179
- "web display": true
180
- },
172
+ "orderTypes": this._setOrderType(eqVariant.properties),
181
173
  "division": eqVariant.properties.division,
182
174
  "backOrderDate": null,
183
175
  "locallyProduced": false,
@@ -193,9 +185,9 @@ const ProductData = {
193
185
  "variantsLabel": eqVariant.properties.variantLabel || "",
194
186
  "groupOffer": false,
195
187
  "personalOffer": false,
196
- "savedEventName": null,
197
- "salesLabel": "",
198
- "eventName": null,
188
+ "savedEventName": eventName,
189
+ "salesLabel": eventLabels,
190
+ "eventName": eventName,
199
191
  "sizeWeight": '',
200
192
  "nettoWeight": "",
201
193
  "searchScore": 0,
@@ -210,6 +202,41 @@ const ProductData = {
210
202
  };
211
203
  },
212
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
+
213
240
  eqProductMapper: function (productDataResponse, skus) {
214
241
  let prod = [];
215
242
  let count = 0;
@@ -227,12 +254,17 @@ const ProductData = {
227
254
  }
228
255
 
229
256
  if (data.sku && data.sku.length > 1) {
230
- data.sku.map(variant => {
257
+ //exclude base product from variants
258
+ data.sku.filter(v => v.identifier.substring(2, 4) !== "55").map(variant => {
231
259
  variants[variant.identifier] = this.eqProductVariantMapper(variant);
232
260
  return variant;
233
261
  });
234
262
  }
235
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 discountedPrice = eventName ? computedPrice : data.sku[count].priceFacets["Regular Price"];
267
+
236
268
  prod = {
237
269
  "sku": data.sku[count].identifier,
238
270
  "globalProductID": data.identifier,
@@ -271,13 +303,13 @@ const ProductData = {
271
303
  "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
272
304
  "pv": data.sku[count].priceFacets.PV,
273
305
  "priceType": "WRTL",
274
- "price": data.sku[count].priceFacets["Regular Price"],
306
+ "price": discountedPrice,
275
307
  "priceMap": {
276
- "WRTL": data.sku[count].priceFacets["Regular Price"],
308
+ "WRTL": productPrice,
277
309
  "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
278
- "WADR": 9999.01,
310
+ "WADR": data.sku[count].priceFacets["Regular Price"],
279
311
  "RTL": data.sku[count].priceFacets["Regular Price"],
280
- "WADW": 9998.01,
312
+ "WADW": data.sku[count].priceFacets["Wholesale Price"],
281
313
  "WHL": data.sku[count].priceFacets["Wholesale Price"],
282
314
  "WWHL": data.sku[count].priceFacets["Wholesale Price"]
283
315
  },
@@ -291,19 +323,7 @@ const ProductData = {
291
323
  "WADW": data.sku[count].priceFacets.PV,
292
324
  "WHL": data.sku[count].priceFacets.PV
293
325
  },
294
- "orderTypes": {
295
- "adr": true,
296
- "order": true,
297
- "zpfc": false,
298
- "zadp": true,
299
- "ars": true,
300
- "kiosk": true,
301
- "mobile": true,
302
- "preferred customer": true,
303
- "retail": true,
304
- "web": true,
305
- "web display": true
306
- },
326
+ "orderTypes": this._setOrderType(data.sku[count].properties),
307
327
  "childSkus": [],
308
328
  "custTypes": this.switchCustType(data.properties.customerTypes),
309
329
  "division": data.properties.division,
@@ -321,9 +341,9 @@ const ProductData = {
321
341
  "variantsLabel": data.sku[count].properties.variantLabel || "",
322
342
  "groupOffer": false,
323
343
  "personalOffer": false,
324
- "savedEventName": null,
325
- "salesLabel": "",
326
- "eventName": null,
344
+ "savedEventName": eventName,
345
+ "salesLabel": eventLabels,
346
+ "eventName": eventName,
327
347
  "sizeWeight": '',
328
348
  "nettoWeight": "",
329
349
  "variants": variants,
@@ -341,7 +361,7 @@ const ProductData = {
341
361
  };
342
362
  let newProduct = new Product(prod);
343
363
  return newProduct
344
- })
364
+ });
345
365
 
346
366
  let data = {
347
367
  products: this._sortProductsBySku(skus, prodArr),
@@ -409,10 +429,69 @@ const ProductData = {
409
429
  return products
410
430
  }
411
431
 
412
- return products.sort(function (a, b) {
432
+ const sortedProducts = products.sort(function (a, b) {
413
433
  return skus.indexOf(a.sku) - skus.indexOf(b.sku);
414
434
  });
415
435
 
436
+ return sortedProducts
437
+
438
+ },
439
+
440
+ /**
441
+ *
442
+ * @param {*} availableChannels
443
+ *
444
+ * This function is use to convert arsPhone,web,kiosk,mobile,subscription
445
+ * to orderType object
446
+ * "adr”
447
+ "order"
448
+ "zpfc"
449
+ "zadp"
450
+ "ars"
451
+ "kiosk"
452
+ "mobile"
453
+ "preferred customer"
454
+ "retail"
455
+ "web"
456
+ "web display"
457
+ */
458
+ _setOrderType: function (properties) {
459
+ let orderTypeArr = {
460
+ "adr": false,
461
+ "order": false,
462
+ "zpfc": false,
463
+ "zadp": false,
464
+ "ars": false,
465
+ "kiosk": false,
466
+ "mobile": false,
467
+ "preferred customer": false,
468
+ "retail": false,
469
+ "web": false,
470
+ "web display": false
471
+ };
472
+ let availableChannelsArr = properties.availableChannels.split(',')
473
+
474
+ availableChannelsArr.forEach(channel => {
475
+ if (channel == 'arsPhone')
476
+ orderTypeArr.ars = true
477
+ if (channel == 'web') {
478
+ orderTypeArr.order = true
479
+ orderTypeArr.web = true
480
+ }
481
+ if (channel == 'kiosk')
482
+ orderTypeArr.kiosk = true
483
+ if (channel == 'mobile')
484
+ orderTypeArr.mobile = true
485
+ if (channel == 'subscription')
486
+ orderTypeArr.adr = true
487
+
488
+ });
489
+ if (properties.retail)
490
+ orderTypeArr.retail = true
491
+ if (properties.prefferredCustomer)
492
+ orderTypeArr['preferred customer'] = true
493
+
494
+ return orderTypeArr;
416
495
  }
417
496
  }
418
497