@nuskin/ns-product-lib 2.19.4 → 2.19.5

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.4",
3
+ "version": "2.19.5",
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": {
@@ -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;