@nuskin/ns-product-lib 2.19.3-mdigi-326.1 → 2.19.3-pur-1420.2
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/graph-ql/product.js +125 -22
package/package.json
CHANGED
package/src/graph-ql/product.js
CHANGED
@@ -72,8 +72,8 @@ async function getProducts(ids, market, locale, config) {
|
|
72
72
|
|
73
73
|
try {
|
74
74
|
const data = await productLib.getProductsById(
|
75
|
-
ids, market, locale,
|
76
|
-
null, 1, okta,
|
75
|
+
ids, market, locale,
|
76
|
+
null, 1, okta,
|
77
77
|
config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod'
|
78
78
|
);
|
79
79
|
if (data && data.products) {
|
@@ -115,7 +115,7 @@ function mapSkusToProducts(skus, products){
|
|
115
115
|
if(product.id) {matched = product.id === sku;}
|
116
116
|
if(product.variants && product.variants.length){
|
117
117
|
product.variants.forEach((variant)=>{
|
118
|
-
matched |= variant.sku === sku;
|
118
|
+
matched |= variant.sku === sku;
|
119
119
|
});
|
120
120
|
}
|
121
121
|
return matched;
|
@@ -129,6 +129,102 @@ function mapSkusToProducts(skus, products){
|
|
129
129
|
|
130
130
|
}
|
131
131
|
|
132
|
+
const addPrice = (productData, priceTypeKey, subKey, priceValue) => {
|
133
|
+
if (!['Points', 'cv', 'price', 'pv'].includes(priceTypeKey)) {
|
134
|
+
// if the priceTypeKey is not one of these, then we don't want it to show.
|
135
|
+
return;
|
136
|
+
}
|
137
|
+
if (priceTypeKey === 'pv') {
|
138
|
+
priceTypeKey = 'psv';
|
139
|
+
}
|
140
|
+
if (priceTypeKey === 'cv') {
|
141
|
+
priceTypeKey = 'csv';
|
142
|
+
}
|
143
|
+
|
144
|
+
if (productData[priceTypeKey] === undefined) {
|
145
|
+
if (priceTypeKey === 'Points') {
|
146
|
+
if (!productData.price) {
|
147
|
+
productData.price = {};
|
148
|
+
}
|
149
|
+
productData.price.PTS = priceValue;
|
150
|
+
return;
|
151
|
+
} else {
|
152
|
+
productData[priceTypeKey] = {};
|
153
|
+
}
|
154
|
+
}
|
155
|
+
productData[priceTypeKey][subKey] = priceValue;
|
156
|
+
}
|
157
|
+
|
158
|
+
function convertPricing(pricing, productData) {
|
159
|
+
if (pricing) {
|
160
|
+
Object.keys(pricing).forEach((channelKey) => {
|
161
|
+
Object.keys(pricing[channelKey]).forEach((contextKey) => {
|
162
|
+
Object.keys(pricing[channelKey][contextKey] || {}).forEach((priceTypeKey) => {
|
163
|
+
const priceValue = pricing[channelKey][contextKey][priceTypeKey];
|
164
|
+
switch (channelKey) {
|
165
|
+
case 'wholesale':
|
166
|
+
switch (contextKey) {
|
167
|
+
case 'webOrder':
|
168
|
+
addPrice(productData, priceTypeKey, 'WWHL', priceValue);
|
169
|
+
break;
|
170
|
+
case 'webAdr':
|
171
|
+
case 'WADW':
|
172
|
+
case 'ADR5':
|
173
|
+
addPrice(productData, priceTypeKey, 'WADW', priceValue);
|
174
|
+
break;
|
175
|
+
case 'order':
|
176
|
+
case 'WHL':
|
177
|
+
addPrice(productData, priceTypeKey, 'WHL', priceValue);
|
178
|
+
break;
|
179
|
+
case 'adr':
|
180
|
+
addPrice(productData, priceTypeKey, 'ADW', priceValue);
|
181
|
+
break;
|
182
|
+
case 'ADR10':
|
183
|
+
case 'WADWD':
|
184
|
+
addPrice(productData, priceTypeKey, 'WADWD', priceValue);
|
185
|
+
break;
|
186
|
+
default:
|
187
|
+
addPrice(
|
188
|
+
productData,
|
189
|
+
priceTypeKey,
|
190
|
+
`${contextKey}-WWHL`,
|
191
|
+
priceValue
|
192
|
+
);
|
193
|
+
break;
|
194
|
+
}
|
195
|
+
break;
|
196
|
+
case 'retail':
|
197
|
+
switch (contextKey) {
|
198
|
+
case 'webOrder':
|
199
|
+
addPrice(productData, priceTypeKey, 'WRTL', priceValue);
|
200
|
+
break;
|
201
|
+
case 'webAdr':
|
202
|
+
addPrice(productData, priceTypeKey, 'WADR', priceValue);
|
203
|
+
break;
|
204
|
+
case 'order':
|
205
|
+
case 'RTL':
|
206
|
+
addPrice(productData, priceTypeKey, 'RTL', priceValue);
|
207
|
+
break;
|
208
|
+
case 'adr':
|
209
|
+
addPrice(productData, priceTypeKey, 'ADR', priceValue);
|
210
|
+
break;
|
211
|
+
default:
|
212
|
+
addPrice(
|
213
|
+
productData,
|
214
|
+
priceTypeKey,
|
215
|
+
`${contextKey}-WRTL`,
|
216
|
+
priceValue
|
217
|
+
);
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
break;
|
221
|
+
}
|
222
|
+
});
|
223
|
+
});
|
224
|
+
});
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
132
228
|
/**
|
133
229
|
*
|
134
230
|
* Map product data to be product card consumable structure *
|
@@ -169,8 +265,8 @@ function mapProduct(product, market, locale, config) {
|
|
169
265
|
"availableQuantity": isBackOrdered ? kitOrVariant.backorderQuantity : kitOrVariant.atpQuantity,
|
170
266
|
"maxQuantity": kitOrVariant.maxQuantity,
|
171
267
|
"points": "",
|
172
|
-
"cv": points
|
173
|
-
"pv": points
|
268
|
+
"cv": points.wholesale ? points.wholesale.cv : 0,
|
269
|
+
"pv": points.wholesale ? points.wholesale.pv : 0,
|
174
270
|
"priceType": "WRTL",
|
175
271
|
"price": pricing.retail,
|
176
272
|
"priceMap": {
|
@@ -187,15 +283,15 @@ function mapProduct(product, market, locale, config) {
|
|
187
283
|
},
|
188
284
|
"cvMap": {
|
189
285
|
...promoData.cvMap,
|
190
|
-
"WWHL": points
|
191
|
-
"WADW": points
|
192
|
-
"WHL": points
|
286
|
+
"WWHL": points.wholesale ? points.wholesale.cv : 0,
|
287
|
+
"WADW": points.subscription ? points.subscription.cv : 0,
|
288
|
+
"WHL": points.wholesale ? points.wholesale.cv : 0
|
193
289
|
},
|
194
290
|
"pvMap": {
|
195
291
|
...promoData.pvMap,
|
196
|
-
"WWHL": points
|
197
|
-
"WADW": points
|
198
|
-
"WHL": points
|
292
|
+
"WWHL": points.wholesale ? points.wholesale.pv : 0,
|
293
|
+
"WADW": points.subscription ? points.subscription.pv : 0,
|
294
|
+
"WHL": points.wholesale ? points.wholesale.pv : 0
|
199
295
|
},
|
200
296
|
"orderTypes": mapOrderTypes(kitOrVariant.availableChannels, kitOrVariant.purchaseTypes),
|
201
297
|
"custTypes": mapCustomerTypes(kitOrVariant.customerTypes),
|
@@ -224,6 +320,13 @@ function mapProduct(product, market, locale, config) {
|
|
224
320
|
}
|
225
321
|
}
|
226
322
|
|
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)
|
329
|
+
|
227
330
|
//map only if it is normal product
|
228
331
|
if (product.variants && !kitBundleProducts) {
|
229
332
|
productDetail.variants = mapVariants(product);
|
@@ -287,8 +390,8 @@ function mapVariants(product) {
|
|
287
390
|
"availableQuantity": variant.availableQuantity,
|
288
391
|
"maxQuantity": variant.maxQuantity,
|
289
392
|
"points": "",
|
290
|
-
"cv": points
|
291
|
-
"pv": points
|
393
|
+
"cv": points.wholesale ? points.wholesale.cv : 0,
|
394
|
+
"pv": points.wholesale ? points.wholesale.pv : 0,
|
292
395
|
"priceType": "WRTL",
|
293
396
|
"price": pricing.retail,
|
294
397
|
"priceMap": {
|
@@ -305,15 +408,15 @@ function mapVariants(product) {
|
|
305
408
|
},
|
306
409
|
"cvMap": {
|
307
410
|
...promoData.cvMap,
|
308
|
-
"WWHL": points
|
309
|
-
"WADW": points
|
310
|
-
"WHL": points
|
411
|
+
"WWHL": points.wholesale ? points.wholesale.cv : 0,
|
412
|
+
"WADW": points.subscription ? points.subscription.cv : 0,
|
413
|
+
"WHL": points.wholesale ? points.wholesale.cv : 0
|
311
414
|
},
|
312
415
|
"pvMap": {
|
313
416
|
...promoData.pvMap,
|
314
|
-
"WWHL": points
|
315
|
-
"WADW": points
|
316
|
-
"WHL": points
|
417
|
+
"WWHL": points.wholesale ? points.wholesale.pv : 0,
|
418
|
+
"WADW": points.subscription ? points.subscription.pv : 0,
|
419
|
+
"WHL": points.wholesale ? points.wholesale.pv : 0
|
317
420
|
},
|
318
421
|
"orderTypes": mapOrderTypes(variant.availableChannels, variant.purchaseTypes),
|
319
422
|
"custTypes": mapCustomerTypes(variant.customerTypes),
|
@@ -557,11 +660,11 @@ function mapPromos(product) {
|
|
557
660
|
promotion = promotion.filter(p=>p.message !== 'Bundle discount')
|
558
661
|
}
|
559
662
|
const offerId = promotion[0].offerId || 'EQPROMO'
|
560
|
-
return {
|
561
|
-
priceMap: {[`${offerId}-WRTL`]: product.price.retailSales, [`${offerId}-WWHL`]: product.price.wholesaleSales},
|
663
|
+
return {
|
664
|
+
priceMap: {[`${offerId}-WRTL`]: product.price.retailSales, [`${offerId}-WWHL`]: product.price.wholesaleSales},
|
562
665
|
cvMap: {[`${offerId}-WWHL`]: product.points.wholesale.cv},
|
563
666
|
pvMap: {[`${offerId}-WWHL`]: product.points.wholesale.pv},
|
564
|
-
message: product.salesLabel || promotion[0].message,
|
667
|
+
message: product.salesLabel || promotion[0].message,
|
565
668
|
offerId
|
566
669
|
}
|
567
670
|
}
|