@nuskin/ns-product-lib 2.21.1 → 2.21.2-mdigi-9080.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.21.1",
3
+ "version": "2.21.2-mdigi-9080.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": {
@@ -70,15 +70,23 @@ async function getProducts(ids, market, locale, config) {
70
70
  }
71
71
 
72
72
  const okta = typeof sessionStorage !== 'undefined' ? parseOktaObject(sessionStorage.oktaTokens) : null;
73
-
73
+ let finalIds= ids;
74
74
  try {
75
+ const uniqueProduct = getUniqueProduct()
76
+ const productsList = uniqueProduct && uniqueProduct.products ? uniqueProduct.products : [];
77
+ const idValue = productsList
78
+ .map(item => item && item.sku ? item.sku : null)
79
+ .filter(Boolean)
80
+ .map(String);
81
+ finalIds = idValue.length ? idValue : ids;
82
+ console.log("the value is of Id is ...... "+idValue)
75
83
  const data = await productLib.getProductsById(
76
- ids, market, locale,
84
+ finalIds, market, locale,
77
85
  null, 1, okta,
78
86
  config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod'
79
87
  );
80
88
  if (data && data.products) {
81
- const mappedProducts = mapSkusToProducts(ids,data.products);
89
+ const mappedProducts = mapSkusToProducts(finalIds,data.products);
82
90
  //use to get default variant based on requested sku
83
91
  for (const {sku, product} of mappedProducts) {
84
92
  config.sku = sku;
@@ -88,7 +96,7 @@ async function getProducts(ids, market, locale, config) {
88
96
  productsData.count = productsData.products.length;
89
97
  }
90
98
  } catch (e) {
91
- console.log(`Unable to fetch products details for SKUs ${ids}`);
99
+ console.log(`Unable to fetch products details for SKUs ${finalIds}`);
92
100
  }
93
101
 
94
102
  return {
@@ -130,6 +138,31 @@ function mapSkusToProducts(skus, products){
130
138
 
131
139
  }
132
140
 
141
+ function deepEqual(varientValue,variantData){
142
+ return JSON.stringify(varientValue)===JSON.stringify(variantData)
143
+ }
144
+
145
+ function getUniqueProduct(){
146
+ if (typeof sessionStorage === 'undefined' || !sessionStorage.getItem('personalOffer')) {
147
+ return { products: [] };
148
+ }
149
+
150
+ const variantCheck = JSON.parse(sessionStorage.getItem('personalOffer')) || { products: [] }
151
+
152
+ if (!variantCheck.products || !Array.isArray(variantCheck.products)) {
153
+ return { products: [] };
154
+ }
155
+
156
+ const unique = [];
157
+ variantCheck.products.forEach(product=>{
158
+ const exists = unique.some(u=> u.sku === product.sku && deepEqual(u.variantSelected, product.variantSelected));
159
+ if(!exists){
160
+ unique.push(product);
161
+ }
162
+ });
163
+ return { products: unique };
164
+ }
165
+
133
166
  function addPrice(productData, priceTypeKey, subKey, priceValue) {
134
167
  if (!['Points', 'cv', 'price', 'pv'].includes(priceTypeKey)) {
135
168
  // if the priceTypeKey is not one of these, then we don't want it to show.