@nuskin/ns-product-lib 2.9.1 → 2.10.0-cx24-4696.2

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [2.10.0-cx24-4696.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.10.0-cx24-4696.1...v2.10.0-cx24-4696.2) (2023-07-27)
2
+
3
+
4
+ ### New
5
+
6
+ * Support for bundles ([dce4424](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/dce44249c9edb5ed264ff012ab9ffa6422fe1dca))
7
+
8
+ # [2.10.0-cx24-4696.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.9.1...v2.10.0-cx24-4696.1) (2023-07-18)
9
+
10
+
11
+ ### New
12
+
13
+ * Support for bundles ([9d696e9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9d696e94522397c2edcb2aa08d2b2755cda81792))
14
+ * Support for bundles ([a945561](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/a94556115f9113b934c6cc993f008b4d539dc965))
15
+
1
16
  ## [2.9.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.9.0...v2.9.1) (2023-07-17)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.9.1",
3
+ "version": "2.10.0-cx24-4696.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": {
@@ -0,0 +1,31 @@
1
+ /**
2
+ * childSKU maps a product variant. Used mainly in subscription.
3
+ *
4
+ * @param {import('.').KitSKUQuantity[]} kits
5
+ * @param {import('.').EquinoxNormalProduct} product
6
+ */
7
+ function childSKUBundle(kits, product) {
8
+ const sku = product.sku.filter(sku => sku.default)[0];
9
+ if (!sku) {
10
+ throw Error('Unable to find the default SKU.');
11
+ }
12
+
13
+ const kit = kits.filter(k => k.sku === product.identifier)[0];
14
+ if (!kit) {
15
+ throw Error('Product in bundle does not exist in the list of available variants.');
16
+ }
17
+
18
+ return {
19
+ productId: product.identifier,
20
+ skuId: sku.identifier,
21
+ type: 'MANDATORY',
22
+ skuQuantity: kit.qty,
23
+ availableChannels: sku.properties.availableChannels,
24
+ inventory: {
25
+ atpQty: sku.inventoryProperties.atpQty,
26
+ backOrdered: sku.inventoryProperties.backOrdered
27
+ }
28
+ }
29
+ }
30
+
31
+ module.exports = childSKUBundle;
@@ -199,8 +199,10 @@
199
199
  */
200
200
  const availableQuantity = require('./availableQuantity');
201
201
  const childSKU = require('./childSKU');
202
+ const childSKUBundles = require('./childSKUBundles');
202
203
 
203
204
  module.exports = {
204
205
  mapAvailableQuantity: availableQuantity,
205
- mapChildSKU: childSKU
206
+ mapChildSKU: childSKU,
207
+ mapChildSKUBundle: childSKUBundles
206
208
  };
@@ -5,11 +5,12 @@ const contentstack = require('./contentstack/contentstack');
5
5
  const Product = require("./product");
6
6
  const CustomerTypes = require('./models/customerTypes');
7
7
  const ProductStatus = require("./models/productStatus");
8
- const { mapAvailableQuantity, mapChildSKU } = require('./equinox-helpers');
8
+ const { mapAvailableQuantity, mapChildSKU, mapChildSKUBundle } = require('./equinox-helpers');
9
9
  const { productNotFoundInterceptor } = require('./equinox-helpers/interceptors');
10
10
 
11
11
  const productTypes = {
12
- kit: 'kit'
12
+ kit: 'kit',
13
+ bundle: 'bundle'
13
14
  };
14
15
 
15
16
  /** @type {*} */
@@ -84,7 +85,7 @@ const ProductData = {
84
85
  locale,
85
86
  storeId: config.store_id
86
87
  },
87
- headers: this.getEquinoxRequestHeaders({shoppingContext}),
88
+ headers: this.getEquinoxRequestHeaders({ shoppingContext }),
88
89
  responseType: 'json',
89
90
  withCredentials: true
90
91
  });
@@ -98,7 +99,7 @@ const ProductData = {
98
99
  'Content-Type': 'application/json'
99
100
  }
100
101
 
101
- if (option.shoppingContext && option.shoppingContext.overrides) {
102
+ if (option.shoppingContext && option.shoppingContext.overrides) {
102
103
  header.showwholesalepricing = option.shoppingContext.overrides.showWholeSalePricing;
103
104
  }
104
105
 
@@ -324,6 +325,7 @@ const ProductData = {
324
325
  * @returns {obj} promotion
325
326
  */
326
327
  getEqProductPromotions(product) {
328
+ let defaultProductPrice;
327
329
 
328
330
  if (!Array.isArray(product.promotion)) {
329
331
  return {
@@ -333,8 +335,11 @@ const ProductData = {
333
335
  eventName: null
334
336
  }
335
337
  }
336
-
337
- const defaultProductPrice = product.totalValue ? product.totalValue.originalPrice : 0;
338
+ if (product.type === "bundle") {
339
+ defaultProductPrice = product.totalValue ? product.totalValue.priceFacets["Regular Price"] : 0;
340
+ } else {
341
+ defaultProductPrice = product.totalValue ? product.totalValue.originalPrice : 0;
342
+ }
338
343
  const computedPrice = product.totalValue && product.totalValue.priceAfterDiscount
339
344
  ? product.totalValue.priceAfterDiscount
340
345
  : 0;
@@ -374,7 +379,7 @@ const ProductData = {
374
379
  for (const productData of productDataResponse) {
375
380
  try {
376
381
  let variants = {};
377
- let product = (productData.type && productData.type === "kit") ? productData : productData.sku[count];
382
+ let product = (productData.type && (productData.type === "kit" || productData.type === "bundle")) ? productData : productData.sku[count];
378
383
  let imageURL = product.properties.imageURL ? product.properties.imageURL : '';
379
384
  let thumbnailImage = imageURL ? imageURL + '?width=40' : '';
380
385
  let productTitle = productData.properties.name;
@@ -573,6 +578,35 @@ const ProductData = {
573
578
  return childSkus;
574
579
  }
575
580
 
581
+ if (product.type === productTypes.bundle) {
582
+ const config = getCachedConfigurations(['Equinox_Markets']).Equinox_Markets;
583
+ const { bundlemandatoryproductids } = product.properties;
584
+ const { locale } = product.tempProperties[0];
585
+
586
+ if (!bundlemandatoryproductids) {
587
+ return [];
588
+ }
589
+
590
+ const bundles = bundlemandatoryproductids.split(',').map(kit => {
591
+ const [sku, qty] = kit.split('~');
592
+ return { sku, qty };
593
+ });
594
+
595
+ const skus = bundles.map(k => k.sku);
596
+ const res = await this.searchEquinoxProduct(skus, locale, config);
597
+ const childSkus = [
598
+ {
599
+ productId: product.identifier,
600
+ skuId: product.identifier,
601
+ type: 'BUNDLE',
602
+ availableChannels: product.properties.availableChannels
603
+ },
604
+ ...res.data.product.map(p => mapChildSKUBundle(bundles, p))
605
+ ];
606
+
607
+ return childSkus;
608
+ }
609
+
576
610
  return [];
577
611
  },
578
612