@nuskin/ns-product-lib 2.19.3 → 2.19.5-pur-1420.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.19.3",
3
+ "version": "2.19.5-pur-1420.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": {
@@ -19,7 +19,7 @@
19
19
  "license": "ISC",
20
20
  "homepage": "https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/blob/master/README.md",
21
21
  "devDependencies": {
22
- "@nuskin/configuration-sdk": "2.3.2",
22
+ "@nuskin/configuration-sdk": "3.0.0",
23
23
  "@nuskin/ns-common-lib": "1.4.7",
24
24
  "@nuskin/ns-util": "4.5.4",
25
25
  "@nuskin/product-lib": "2.2.1",
@@ -36,7 +36,7 @@
36
36
  "prettier": "1.19.1"
37
37
  },
38
38
  "peerDependencies": {
39
- "@nuskin/configuration-sdk": "2.x",
39
+ "@nuskin/configuration-sdk": "3.x",
40
40
  "@nuskin/ns-common-lib": "1.x",
41
41
  "@nuskin/ns-util": "4.x",
42
42
  "axios": "1.6.7"
@@ -129,7 +129,7 @@ function mapSkusToProducts(skus, products){
129
129
 
130
130
  }
131
131
 
132
- const addPrice = (productData, priceTypeKey, subKey, priceValue) => {
132
+ function addPrice(productData, priceTypeKey, subKey, priceValue) {
133
133
  if (!['Points', 'cv', 'price', 'pv'].includes(priceTypeKey)) {
134
134
  // if the priceTypeKey is not one of these, then we don't want it to show.
135
135
  return;
@@ -155,7 +155,7 @@ const addPrice = (productData, priceTypeKey, subKey, priceValue) => {
155
155
  productData[priceTypeKey][subKey] = priceValue;
156
156
  }
157
157
 
158
- function convertPricing(pricing, productData) {
158
+ function convertPricingJson(pricing, productData) {
159
159
  if (pricing) {
160
160
  Object.keys(pricing).forEach((channelKey) => {
161
161
  Object.keys(pricing[channelKey]).forEach((contextKey) => {
@@ -225,6 +225,17 @@ function convertPricing(pricing, productData) {
225
225
  }
226
226
  }
227
227
 
228
+ function mapPricingJson(productDetail, kitOrVariant, isContentStack) {
229
+ if (isContentStack) {
230
+ const pricingMap = JSON.parse(kitOrVariant.pricingJson)
231
+ const convertedMap = {}
232
+ convertPricingJson(pricingMap, convertedMap)
233
+ Object.assign(productDetail.priceMap, convertedMap.price)
234
+ Object.assign(productDetail.cvMap, convertedMap.csv)
235
+ Object.assign(productDetail.pvMap, convertedMap.psv)
236
+ }
237
+ }
238
+
228
239
  /**
229
240
  *
230
241
  * Map product data to be product card consumable structure *
@@ -320,16 +331,12 @@ function mapProduct(product, market, locale, config) {
320
331
  }
321
332
  }
322
333
 
323
- const pricingMap = JSON.parse(kitOrVariant.pricingJson)
324
- const convertedMap = {}
325
- convertPricing(pricingMap, convertedMap)
326
- Object.assign(productDetail.priceMap, convertedMap.price)
327
- Object.assign(productDetail.cvMap, convertedMap.csv)
328
- Object.assign(productDetail.pvMap, convertedMap.psv)
334
+ const isContentStack = product.productDataSource.source === 'contentstack'
335
+ mapPricingJson(productDetail, kitOrVariant, isContentStack)
329
336
 
330
337
  //map only if it is normal product
331
338
  if (product.variants && !kitBundleProducts) {
332
- productDetail.variants = mapVariants(product);
339
+ productDetail.variants = mapVariants(product, isContentStack);
333
340
  }
334
341
 
335
342
  if (kitBundleProducts) {
@@ -354,9 +361,10 @@ function mapProduct(product, market, locale, config) {
354
361
  /**
355
362
  * Map product variants
356
363
  * @param {*} product
364
+ * @param {boolean} isContentStack
357
365
  * @returns {Array<object>} productVariants
358
366
  */
359
- function mapVariants(product) {
367
+ function mapVariants(product, isContentStack) {
360
368
 
361
369
  //return if it has no variant
362
370
  if (!product.variants || (product.variants && product.variants.length === 1)) {
@@ -445,6 +453,7 @@ function mapVariants(product) {
445
453
  productStatus: mapProductStatus(variant.status.status)
446
454
  }
447
455
  }
456
+ mapPricingJson(variants[sku], variant, isContentStack)
448
457
  });
449
458
 
450
459
  return variants;
@@ -651,7 +660,8 @@ function mapProductStatus(status) {
651
660
 
652
661
  /* istanbul ignore next */
653
662
  function mapPromos(product) {
654
- if ((product.price.retailSales !== null && product.price.retailSales >= 0) || (product.price.wholesaleSales !== null && product.price.wholesaleSales >= 0)) {
663
+ if ((product.price.retailSales !== null && product.price.retailSales >= 0) ||
664
+ (product.price.wholesaleSales !== null && product.price.wholesaleSales >= 0)) {
655
665
  if (product.pricingJson) {
656
666
  const parsedPricing = JSON.parse(product.pricingJson)
657
667
  let promotion = parsedPricing.promotion
@@ -671,8 +681,10 @@ function mapPromos(product) {
671
681
  if (parsedPricing.retail) {
672
682
  const filter = ['adr', 'order', 'webAdr', 'webOrder']
673
683
  const priceMap = {}, cvMap = {}, pvMap = {}
674
- const retailActiveEvents = Object.fromEntries(Object.entries(parsedPricing.retail).filter(([k]) => !filter.includes(k)));
675
- const wholesaleActiveEvents = Object.fromEntries(Object.entries(parsedPricing.wholesale).filter(([k]) => !filter.includes(k)));
684
+ const retailActiveEvents =
685
+ Object.fromEntries(Object.entries(parsedPricing.retail).filter(([k]) => !filter.includes(k)));
686
+ const wholesaleActiveEvents =
687
+ Object.fromEntries(Object.entries(parsedPricing.wholesale).filter(([k]) => !filter.includes(k)));
676
688
  let offerId = null
677
689
  for (const key in retailActiveEvents) {
678
690
  if (Object.hasOwnProperty.call(retailActiveEvents, key)) {
@@ -694,7 +706,7 @@ function mapPromos(product) {
694
706
  }
695
707
  return { message: product.salesLabel, offerId: null, priceMap: {}, cvMap: {}, pvMap: {} }
696
708
  }
697
- return {message: null, offerId: null}
709
+ return {message: product.salesLabel, offerId: null}
698
710
  }
699
711
 
700
712
  /* istanbul ignore next */