@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.18.0-brw-4218.1",
3
+ "version": "2.18.0-brw-4218.2",
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": {
@@ -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
- const defaultVariant = product.variants[0];
360
- return {
361
- productId: product.id,
362
- skuId: defaultVariant.sku,
363
- type: 'MANDATORY',
364
- skuQuantity: kitProduct.quantity,
365
- availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
366
- inventory: {
367
- atpQty: defaultVariant.atpQuantity,
368
- backOrdered: defaultVariant.status.inventory === 'backordered',
369
- backOrderedQty: defaultVariant.backorderQuantity
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
  });