@nuskin/ns-product-lib 2.19.4 → 2.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/graph-ql/product.js +19 -10
package/package.json
CHANGED
package/src/graph-ql/product.js
CHANGED
@@ -129,7 +129,7 @@ function mapSkusToProducts(skus, products){
|
|
129
129
|
|
130
130
|
}
|
131
131
|
|
132
|
-
|
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
|
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
|
324
|
-
|
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;
|