@nuskin/ns-product-lib 2.17.2 → 2.17.4

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.17.2",
3
+ "version": "2.17.4",
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": {
@@ -438,20 +438,38 @@ function mapChildSKU(kitBundleProducts) {
438
438
  if (!kitBundleProducts || !kitBundleProducts.kitProducts) {
439
439
  return [];
440
440
  }
441
-
441
+ const personalOffer = sessionStorage.getItem('personalOffer') ? JSON.parse(sessionStorage.getItem('personalOffer')) : false
442
442
  return kitBundleProducts.kitProducts.map((kitProduct) => {
443
443
  const { product } = kitProduct;
444
- const defaultVariant = product.variants[0];
445
- return {
446
- productId: product.id,
447
- skuId: defaultVariant.sku,
448
- type: 'MANDATORY',
449
- skuQuantity: kitProduct.quantity,
450
- availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
451
- inventory: {
452
- atpQty: defaultVariant.availableQuantity,
453
- backOrdered: defaultVariant.status.isBackordered,
454
- backOrderedQty: defaultVariant.availableQuantity
444
+ if (product.variants.length > 1 && typeof personalOffer === 'object') {
445
+ return product.variants.map((variant) => {
446
+ return {
447
+ productId: product.id,
448
+ skuId: variant.sku,
449
+ type: kitProduct.isMandatory ? 'MANDATORY' : 'OPTIONAL',
450
+ skuQuantity: kitProduct.quantity,
451
+ // eslint-disable-next-line max-len
452
+ availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
453
+ inventory: {
454
+ atpQty: variant.availableQuantity,
455
+ backOrdered: variant.status.isBackordered,
456
+ backOrderedQty: variant.availableQuantity
457
+ }
458
+ }
459
+ })
460
+ } else {
461
+ const defaultVariant = product.variants[0];
462
+ return {
463
+ productId: product.id,
464
+ skuId: defaultVariant.sku,
465
+ type: kitProduct.isMandatory ? 'MANDATORY' : 'OPTIONAL',
466
+ skuQuantity: kitProduct.quantity,
467
+ availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
468
+ inventory: {
469
+ atpQty: defaultVariant.availableQuantity,
470
+ backOrdered: defaultVariant.status.isBackordered,
471
+ backOrderedQty: defaultVariant.availableQuantity
472
+ }
455
473
  }
456
474
  }
457
475
  });