@nuskin/ns-product-lib 2.18.0-brw-4218.1 → 2.18.0-brw-4218.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 +43 -16
- package/src/product.js +1 -1
package/package.json
CHANGED
package/src/graph-ql/product.js
CHANGED
@@ -28,7 +28,6 @@ async function getProduct(id, market, locale, config) {
|
|
28
28
|
env: config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod',
|
29
29
|
okta
|
30
30
|
});
|
31
|
-
|
32
31
|
if (data && data.data) {
|
33
32
|
//use to get default variant based on requested sku
|
34
33
|
config.sku = id;
|
@@ -65,6 +64,10 @@ async function getProducts(ids, market, locale, config) {
|
|
65
64
|
count: 0
|
66
65
|
};
|
67
66
|
|
67
|
+
if (!Array.isArray(ids)) {
|
68
|
+
ids = [ids]
|
69
|
+
}
|
70
|
+
|
68
71
|
const okta = typeof sessionStorage !== 'undefined' ? parseOktaObject(sessionStorage.oktaTokens) : null;
|
69
72
|
|
70
73
|
try {
|
@@ -110,7 +113,7 @@ function mapSkusToProducts(skus, products){
|
|
110
113
|
const matchedProducts = products.filter((product)=>{
|
111
114
|
let matched = false;
|
112
115
|
if(product.id) {matched = product.id === sku;}
|
113
|
-
if(product.variants.length){
|
116
|
+
if(product.variants && product.variants.length){
|
114
117
|
product.variants.forEach((variant)=>{
|
115
118
|
matched |= variant.sku === sku;
|
116
119
|
});
|
@@ -353,23 +356,41 @@ function mapChildSKU(kitBundleProducts) {
|
|
353
356
|
if (!kitBundleProducts || !kitBundleProducts.kitProducts) {
|
354
357
|
return [];
|
355
358
|
}
|
356
|
-
|
359
|
+
const personalOffer = typeof sessionStorage !== 'undefined' && sessionStorage.getItem('personalOffer') ? JSON.parse(sessionStorage.getItem('personalOffer')) : false
|
357
360
|
return kitBundleProducts.kitProducts.map((kitProduct) => {
|
358
361
|
const { product } = kitProduct;
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
362
|
+
if (product.variants.length > 1 && typeof personalOffer === 'object') {
|
363
|
+
return product.variants.map((variant) => {
|
364
|
+
return {
|
365
|
+
productId: product.id,
|
366
|
+
skuId: variant.sku,
|
367
|
+
type: kitProduct.isMandatory ? 'MANDATORY' : 'OPTIONAL',
|
368
|
+
skuQuantity: kitProduct.quantity,
|
369
|
+
// eslint-disable-next-line max-len
|
370
|
+
availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
|
371
|
+
inventory: {
|
372
|
+
atpQty: variant.atpQuantity,
|
373
|
+
backOrdered: variant.status.inventory === 'backordered',
|
374
|
+
backOrderedQty: variant.backorderQuantity
|
375
|
+
}
|
376
|
+
}
|
377
|
+
})
|
378
|
+
} else {
|
379
|
+
const defaultVariant = product.variants[0];
|
380
|
+
return {
|
381
|
+
productId: product.id,
|
382
|
+
skuId: defaultVariant.sku,
|
383
|
+
type: kitProduct.isMandatory ? 'MANDATORY' : 'OPTIONAL',
|
384
|
+
skuQuantity: kitProduct.quantity,
|
385
|
+
availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
|
386
|
+
inventory: {
|
387
|
+
atpQty: defaultVariant.atpQuantity,
|
388
|
+
backOrdered: defaultVariant.status.inventory === 'backordered',
|
389
|
+
backOrderedQty: defaultVariant.backorderQuantity
|
390
|
+
}
|
370
391
|
}
|
371
392
|
}
|
372
|
-
});
|
393
|
+
}).flat();
|
373
394
|
}
|
374
395
|
|
375
396
|
|
@@ -479,9 +500,16 @@ function mapOrderTypes(availableChannels, purchaseTypes) {
|
|
479
500
|
orderTypes.web = true
|
480
501
|
orderTypes.order = true
|
481
502
|
}
|
503
|
+
if (purchaseTypes && !purchaseTypes.buyOnce) {
|
504
|
+
orderTypes.web = false
|
505
|
+
orderTypes.order = false
|
506
|
+
}
|
482
507
|
if (purchaseTypes && purchaseTypes.subscription) {
|
483
508
|
orderTypes.adr = true
|
484
509
|
}
|
510
|
+
if (purchaseTypes && !purchaseTypes.subscription) {
|
511
|
+
orderTypes.adr = false
|
512
|
+
}
|
485
513
|
|
486
514
|
return orderTypes;
|
487
515
|
}
|
@@ -514,7 +542,6 @@ function mapProductStatus(status) {
|
|
514
542
|
newStatus = ProductStatus.NotReleasedForSale;
|
515
543
|
break;
|
516
544
|
}
|
517
|
-
|
518
545
|
return newStatus;
|
519
546
|
}
|
520
547
|
|
package/src/product.js
CHANGED
@@ -393,7 +393,7 @@ const Product = function (productData) {
|
|
393
393
|
Object.keys(this.priceMap).forEach(priceTypeKey => {
|
394
394
|
const eventPriceType = priceTypeKey.substring(0, priceTypeKey.indexOf(`-${this.priceType}`));
|
395
395
|
|
396
|
-
if (eventPriceType) {
|
396
|
+
if (eventPriceType && this.priceMap[eventPriceType]) {
|
397
397
|
eventPriceTypes.push(eventPriceType);
|
398
398
|
}
|
399
399
|
});
|