@nuskin/ns-product-lib 2.6.0-cx24-3464.11 → 2.6.0-cx24-3464.13

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.6.0-cx24-3464.13](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.6.0-cx24-3464.12...v2.6.0-cx24-3464.13) (2023-03-11)
2
+
3
+
4
+ ### Update
5
+
6
+ * get child skus to be used for add-to-cart #CX24-3464 ([b865b9d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b865b9d4705d2958093ccf7f2156e7ccfb0a3efb)), closes [#CX24-3464](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3464)
7
+ * get child skus to be used for add-to-cart #CX24-3464 ([8ccde01](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/8ccde019f07af4dbeeae312fc31d2b3130f54334)), closes [#CX24-3464](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3464)
8
+
9
+ # [2.6.0-cx24-3464.12](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.6.0-cx24-3464.11...v2.6.0-cx24-3464.12) (2023-03-11)
10
+
11
+
12
+ ### Update
13
+
14
+ * get child skus to be used for add-to-cart #CX24-3464 ([3ecdf5f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3ecdf5f9722f78256a1e5f48e368fcee3662856d)), closes [#CX24-3464](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3464)
15
+
1
16
  # [2.6.0-cx24-3464.11](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.6.0-cx24-3464.10...v2.6.0-cx24-3464.11) (2023-03-10)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.6.0-cx24-3464.11",
3
+ "version": "2.6.0-cx24-3464.13",
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,19 @@
1
+ /**
2
+ * mapAvailableQuantity returns the atp (available-to-purchase) quantity.
3
+ * @param {import('./').Product} product
4
+ * @returns {number}
5
+ */
6
+ function mapAvailableQuantity(product) {
7
+ if (product.inventoryProperties) {
8
+ return product.inventoryProperties.atpQty;
9
+ }
10
+
11
+ if (product.childSkus && product.childSkus.length > 0) {
12
+ const quantities = product.childSkus.map(cs => cs.inventory.atpQty);
13
+ return Math.min(...quantities);
14
+ }
15
+
16
+ return 0;
17
+ }
18
+
19
+ module.exports = mapAvailableQuantity;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @typedef Product
3
+ * @type {object}
4
+ * @property {ChildSku[]} childSkus
5
+ * @property {Inventory} [inventoryProperties]
6
+ *
7
+ * @typedef ChildSku
8
+ * @type {object}
9
+ * @property {string} productId
10
+ * @property {string} skuId
11
+ * @property {string} type
12
+ * @property {number} skuQuantity
13
+ * @property {string} availableChannels
14
+ * @property {Inventory} inventory
15
+ *
16
+ * @typedef Inventory
17
+ * @type {object}
18
+ * @property {number} atpQty
19
+ * @property {boolean} backOrdered
20
+ */
21
+ const availableQuantity = require('./availableQuantity');
22
+
23
+ module.exports = {
24
+ availableQuantity
25
+ };
@@ -5,6 +5,7 @@ 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 { availableQuantity } = require('./equinox-helpers');
8
9
 
9
10
  const productTypes = {
10
11
  kit: 'kit'
@@ -409,7 +410,7 @@ const ProductData = {
409
410
  }
410
411
  ],
411
412
  "scanQualified": productData.properties.scanQualifiedCount,
412
- "availableQuantity": (product.inventoryProperties) ? product.inventoryProperties.atpQty : 0,
413
+ "availableQuantity": availableQuantity(product),
413
414
  "maxQuantity": 999,
414
415
  "points": "",
415
416
  "cv": (product.priceFacets.CV) ? product.priceFacets.CV : '',
@@ -534,7 +535,10 @@ const ProductData = {
534
535
  type: 'MANDATORY',
535
536
  skuQuantity: kit.qty,
536
537
  availableChannels: sku.properties.availableChannels,
537
- backOrdered: sku.inventoryProperties.backOrdered
538
+ inventory: {
539
+ atpQty: sku.inventoryProperties.atpQty,
540
+ backOrdered: sku.inventoryProperties.backOrdered
541
+ }
538
542
  }
539
543
  },
540
544