@nuskin/ns-product-lib 2.21.1 → 2.21.2-mdigi-9080.1
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 +1 -1
- package/src/graph-ql/product.js +34 -1
package/package.json
CHANGED
package/src/graph-ql/product.js
CHANGED
|
@@ -72,8 +72,16 @@ async function getProducts(ids, market, locale, config) {
|
|
|
72
72
|
const okta = typeof sessionStorage !== 'undefined' ? parseOktaObject(sessionStorage.oktaTokens) : null;
|
|
73
73
|
|
|
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
|
+
const finalIds = idValue.length ? idValue : ids;
|
|
82
|
+
console.log("the value is of Id is ...... "+idValue)
|
|
75
83
|
const data = await productLib.getProductsById(
|
|
76
|
-
|
|
84
|
+
finalIds, market, locale,
|
|
77
85
|
null, 1, okta,
|
|
78
86
|
config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod'
|
|
79
87
|
);
|
|
@@ -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.
|