@nuskin/ns-product-lib 2.4.1-cx12-5910.1 → 2.4.1-cx24-2612.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +3 -2
- package/package.json +1 -1
- package/src/contentstack/contentstack.js +1 -12
- package/src/productData.js +23 -4
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
## [2.4.1-
|
1
|
+
## [2.4.1-cx24-2612.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.0...v2.4.1-cx24-2612.1) (2022-11-03)
|
2
2
|
|
3
3
|
|
4
4
|
### Fix
|
5
5
|
|
6
|
-
*
|
6
|
+
* [Equinox market] Admin > Move up/down/top/bottom of featured products and edit bundle is not working ([767efcd](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/767efcd821764a83212321707f1f1db64527e48e))
|
7
|
+
* [Equinox market] Admin > Move up/down/top/bottom of featured products and edit bundle is not working ([bfbb4a4](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bfbb4a4902faa5a17904e47d37aa935199a78d2e))
|
7
8
|
|
8
9
|
# [2.4.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.4.0) (2022-10-26)
|
9
10
|
|
package/package.json
CHANGED
@@ -3,19 +3,8 @@ const axios = require('axios');
|
|
3
3
|
const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
|
4
4
|
const config = require('./environment');
|
5
5
|
|
6
|
-
let env = 'unknown';
|
7
|
-
|
8
|
-
// ns-product-lib should be multi-platform compatible i.e. lambda, web, or react native etc.
|
9
|
-
try {
|
10
|
-
env = getEnvironmentFromUrl(window.location.host);
|
11
|
-
} catch (error) {
|
12
|
-
console.log("getting env from url not supported. window is likely unavailable:");
|
13
|
-
console.log("Name: ", error.name);
|
14
|
-
console.log("Message: ", error.message);
|
15
|
-
console.log("Stack Trace: ", error.stack);
|
16
|
-
}
|
17
|
-
|
18
6
|
// contentstack HTTP service
|
7
|
+
const env = getEnvironmentFromUrl(window.location.host);
|
19
8
|
const envConfig = config.getCredentials(env);
|
20
9
|
const baseURL = `${envConfig.url}/stacks/${envConfig.apiKey}?environment=${envConfig.env}`;
|
21
10
|
const headers = {
|
package/src/productData.js
CHANGED
@@ -30,7 +30,6 @@ const ProductData = {
|
|
30
30
|
axios.defaults.withCredentials = true;
|
31
31
|
|
32
32
|
const url = await contentstack.getKongUrl() + `/orchestrationservices/storefront/catalogs/search/`;
|
33
|
-
console.log("Dynamic URL", url)
|
34
33
|
const href = `${url}?filter=${encodeURI(filter)}`;
|
35
34
|
const response = await axios.request({
|
36
35
|
method: 'get',
|
@@ -44,7 +43,7 @@ const ProductData = {
|
|
44
43
|
});
|
45
44
|
|
46
45
|
if (response.data.product) {
|
47
|
-
return this.eqProductMapper(response.data.product);
|
46
|
+
return this.eqProductMapper(response.data.product, skus);
|
48
47
|
}
|
49
48
|
|
50
49
|
return {
|
@@ -211,7 +210,7 @@ const ProductData = {
|
|
211
210
|
};
|
212
211
|
},
|
213
212
|
|
214
|
-
eqProductMapper: function (productDataResponse) {
|
213
|
+
eqProductMapper: function (productDataResponse, skus) {
|
215
214
|
let prod = [];
|
216
215
|
let count = 0;
|
217
216
|
let variants = {};
|
@@ -345,7 +344,7 @@ const ProductData = {
|
|
345
344
|
})
|
346
345
|
|
347
346
|
let data = {
|
348
|
-
products: prodArr,
|
347
|
+
products: this._sortProductsBySku(skus, prodArr),
|
349
348
|
count: productDataResponse.length
|
350
349
|
};
|
351
350
|
return {
|
@@ -396,6 +395,26 @@ const ProductData = {
|
|
396
395
|
if (custType.includes('Preferred Customer/Member'))
|
397
396
|
newCustType.push(30)
|
398
397
|
return newCustType.toString()
|
398
|
+
},
|
399
|
+
|
400
|
+
/**
|
401
|
+
* Sorts the product by sku
|
402
|
+
* @param {Array} skus - the skus arrangment which the sorting will base out of
|
403
|
+
* @param {Array} products - this products to be sorted
|
404
|
+
*/
|
405
|
+
|
406
|
+
_sortProductsBySku: function (skus, products) {
|
407
|
+
|
408
|
+
if(!skus || !products || products.length === 1) {
|
409
|
+
return products
|
410
|
+
}
|
411
|
+
|
412
|
+
const sortedProducts = products.sort(function (a, b) {
|
413
|
+
return skus.indexOf(a.sku) - skus.indexOf(b.sku);
|
414
|
+
});
|
415
|
+
|
416
|
+
return sortedProducts
|
417
|
+
|
399
418
|
}
|
400
419
|
}
|
401
420
|
|