@nuskin/ns-product-lib 2.9.1 → 2.10.0-cx24-4696.1
Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# [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)
|
2
|
+
|
3
|
+
|
4
|
+
### New
|
5
|
+
|
6
|
+
* Support for bundles ([9d696e9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9d696e94522397c2edcb2aa08d2b2755cda81792))
|
7
|
+
* Support for bundles ([a945561](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/a94556115f9113b934c6cc993f008b4d539dc965))
|
8
|
+
|
1
9
|
## [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
10
|
|
3
11
|
|
package/package.json
CHANGED
@@ -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
|
};
|
package/src/productData.js
CHANGED
@@ -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 &&
|
102
|
+
if (option.shoppingContext && option.shoppingContext.overrides) {
|
102
103
|
header.showwholesalepricing = option.shoppingContext.overrides.showWholeSalePricing;
|
103
104
|
}
|
104
105
|
|
@@ -374,7 +375,7 @@ const ProductData = {
|
|
374
375
|
for (const productData of productDataResponse) {
|
375
376
|
try {
|
376
377
|
let variants = {};
|
377
|
-
let product = (productData.type && productData.type === "kit") ? productData : productData.sku[count];
|
378
|
+
let product = (productData.type && (productData.type === "kit" || productData.type === "bundle")) ? productData : productData.sku[count];
|
378
379
|
let imageURL = product.properties.imageURL ? product.properties.imageURL : '';
|
379
380
|
let thumbnailImage = imageURL ? imageURL + '?width=40' : '';
|
380
381
|
let productTitle = productData.properties.name;
|
@@ -573,6 +574,35 @@ const ProductData = {
|
|
573
574
|
return childSkus;
|
574
575
|
}
|
575
576
|
|
577
|
+
if (product.type === productTypes.bundle) {
|
578
|
+
const config = getCachedConfigurations(['Equinox_Markets']).Equinox_Markets;
|
579
|
+
const { bundlemandatoryproductids } = product.properties;
|
580
|
+
const { locale } = product.tempProperties[0];
|
581
|
+
|
582
|
+
if (!bundlemandatoryproductids) {
|
583
|
+
return [];
|
584
|
+
}
|
585
|
+
|
586
|
+
const bundles = bundlemandatoryproductids.split(',').map(kit => {
|
587
|
+
const [sku, qty] = kit.split('~');
|
588
|
+
return { sku, qty };
|
589
|
+
});
|
590
|
+
|
591
|
+
const skus = bundles.map(k => k.sku);
|
592
|
+
const res = await this.searchEquinoxProduct(skus, locale, config);
|
593
|
+
const childSkus = [
|
594
|
+
{
|
595
|
+
productId: product.identifier,
|
596
|
+
skuId: product.identifier,
|
597
|
+
type: 'BUNDLE',
|
598
|
+
availableChannels: product.properties.availableChannels
|
599
|
+
},
|
600
|
+
...res.data.product.map(p => mapChildSKUBundle(bundles, p))
|
601
|
+
];
|
602
|
+
|
603
|
+
return childSkus;
|
604
|
+
}
|
605
|
+
|
576
606
|
return [];
|
577
607
|
},
|
578
608
|
|