@nuskin/ns-product-lib 2.19.2 → 2.19.3-pur-1420.1
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/src/graph-ql/product.js +109 -6
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nuskin/ns-product-lib",
|
3
|
-
"version": "2.19.
|
3
|
+
"version": "2.19.3-pur-1420.1",
|
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": {
|
@@ -19,7 +19,7 @@
|
|
19
19
|
"license": "ISC",
|
20
20
|
"homepage": "https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/blob/master/README.md",
|
21
21
|
"devDependencies": {
|
22
|
-
"@nuskin/configuration-sdk": "
|
22
|
+
"@nuskin/configuration-sdk": "3.0.0",
|
23
23
|
"@nuskin/ns-common-lib": "1.4.7",
|
24
24
|
"@nuskin/ns-util": "4.5.4",
|
25
25
|
"@nuskin/product-lib": "2.2.1",
|
@@ -36,7 +36,7 @@
|
|
36
36
|
"prettier": "1.19.1"
|
37
37
|
},
|
38
38
|
"peerDependencies": {
|
39
|
-
"@nuskin/configuration-sdk": "
|
39
|
+
"@nuskin/configuration-sdk": "3.x",
|
40
40
|
"@nuskin/ns-common-lib": "1.x",
|
41
41
|
"@nuskin/ns-util": "4.x",
|
42
42
|
"axios": "1.6.7"
|
package/src/graph-ql/product.js
CHANGED
@@ -72,8 +72,8 @@ async function getProducts(ids, market, locale, config) {
|
|
72
72
|
|
73
73
|
try {
|
74
74
|
const data = await productLib.getProductsById(
|
75
|
-
ids, market, locale,
|
76
|
-
null, 1, okta,
|
75
|
+
ids, market, locale,
|
76
|
+
null, 1, okta,
|
77
77
|
config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod'
|
78
78
|
);
|
79
79
|
if (data && data.products) {
|
@@ -115,7 +115,7 @@ function mapSkusToProducts(skus, products){
|
|
115
115
|
if(product.id) {matched = product.id === sku;}
|
116
116
|
if(product.variants && product.variants.length){
|
117
117
|
product.variants.forEach((variant)=>{
|
118
|
-
matched |= variant.sku === sku;
|
118
|
+
matched |= variant.sku === sku;
|
119
119
|
});
|
120
120
|
}
|
121
121
|
return matched;
|
@@ -129,6 +129,102 @@ function mapSkusToProducts(skus, products){
|
|
129
129
|
|
130
130
|
}
|
131
131
|
|
132
|
+
const addPrice = (productData, priceTypeKey, subKey, priceValue) => {
|
133
|
+
if (!['Points', 'cv', 'price', 'pv'].includes(priceTypeKey)) {
|
134
|
+
// if the priceTypeKey is not one of these, then we don't want it to show.
|
135
|
+
return;
|
136
|
+
}
|
137
|
+
if (priceTypeKey === 'pv') {
|
138
|
+
priceTypeKey = 'psv';
|
139
|
+
}
|
140
|
+
if (priceTypeKey === 'cv') {
|
141
|
+
priceTypeKey = 'csv';
|
142
|
+
}
|
143
|
+
|
144
|
+
if (productData[priceTypeKey] === undefined) {
|
145
|
+
if (priceTypeKey === 'Points') {
|
146
|
+
if (!productData.price) {
|
147
|
+
productData.price = {};
|
148
|
+
}
|
149
|
+
productData.price.PTS = priceValue;
|
150
|
+
return;
|
151
|
+
} else {
|
152
|
+
productData[priceTypeKey] = {};
|
153
|
+
}
|
154
|
+
}
|
155
|
+
productData[priceTypeKey][subKey] = priceValue;
|
156
|
+
}
|
157
|
+
|
158
|
+
function convertPricing(pricing, productData) {
|
159
|
+
if (pricing) {
|
160
|
+
Object.keys(pricing).forEach((channelKey) => {
|
161
|
+
Object.keys(pricing[channelKey]).forEach((contextKey) => {
|
162
|
+
Object.keys(pricing[channelKey][contextKey] || {}).forEach((priceTypeKey) => {
|
163
|
+
const priceValue = pricing[channelKey][contextKey][priceTypeKey];
|
164
|
+
switch (channelKey) {
|
165
|
+
case 'wholesale':
|
166
|
+
switch (contextKey) {
|
167
|
+
case 'webOrder':
|
168
|
+
addPrice(productData, priceTypeKey, 'WWHL', priceValue);
|
169
|
+
break;
|
170
|
+
case 'webAdr':
|
171
|
+
case 'WADW':
|
172
|
+
case 'ADR5':
|
173
|
+
addPrice(productData, priceTypeKey, 'WADW', priceValue);
|
174
|
+
break;
|
175
|
+
case 'order':
|
176
|
+
case 'WHL':
|
177
|
+
addPrice(productData, priceTypeKey, 'WHL', priceValue);
|
178
|
+
break;
|
179
|
+
case 'adr':
|
180
|
+
addPrice(productData, priceTypeKey, 'ADW', priceValue);
|
181
|
+
break;
|
182
|
+
case 'ADR10':
|
183
|
+
case 'WADWD':
|
184
|
+
addPrice(productData, priceTypeKey, 'WADWD', priceValue);
|
185
|
+
break;
|
186
|
+
default:
|
187
|
+
addPrice(
|
188
|
+
productData,
|
189
|
+
priceTypeKey,
|
190
|
+
`${contextKey}-WWHL`,
|
191
|
+
priceValue
|
192
|
+
);
|
193
|
+
break;
|
194
|
+
}
|
195
|
+
break;
|
196
|
+
case 'retail':
|
197
|
+
switch (contextKey) {
|
198
|
+
case 'webOrder':
|
199
|
+
addPrice(productData, priceTypeKey, 'WRTL', priceValue);
|
200
|
+
break;
|
201
|
+
case 'webAdr':
|
202
|
+
addPrice(productData, priceTypeKey, 'WADR', priceValue);
|
203
|
+
break;
|
204
|
+
case 'order':
|
205
|
+
case 'RTL':
|
206
|
+
addPrice(productData, priceTypeKey, 'RTL', priceValue);
|
207
|
+
break;
|
208
|
+
case 'adr':
|
209
|
+
addPrice(productData, priceTypeKey, 'ADR', priceValue);
|
210
|
+
break;
|
211
|
+
default:
|
212
|
+
addPrice(
|
213
|
+
productData,
|
214
|
+
priceTypeKey,
|
215
|
+
`${contextKey}-WRTL`,
|
216
|
+
priceValue
|
217
|
+
);
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
break;
|
221
|
+
}
|
222
|
+
});
|
223
|
+
});
|
224
|
+
});
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
132
228
|
/**
|
133
229
|
*
|
134
230
|
* Map product data to be product card consumable structure *
|
@@ -224,6 +320,13 @@ function mapProduct(product, market, locale, config) {
|
|
224
320
|
}
|
225
321
|
}
|
226
322
|
|
323
|
+
const pricingMap = JSON.parse(kitOrVariant.pricingJson)
|
324
|
+
const convertedMap = {}
|
325
|
+
convertPricing(pricingMap, convertedMap)
|
326
|
+
Object.assign(productDetail.priceMap, convertedMap.price)
|
327
|
+
Object.assign(productDetail.cvMap, convertedMap.csv)
|
328
|
+
Object.assign(productDetail.pvMap, convertedMap.psv)
|
329
|
+
|
227
330
|
//map only if it is normal product
|
228
331
|
if (product.variants && !kitBundleProducts) {
|
229
332
|
productDetail.variants = mapVariants(product);
|
@@ -557,11 +660,11 @@ function mapPromos(product) {
|
|
557
660
|
promotion = promotion.filter(p=>p.message !== 'Bundle discount')
|
558
661
|
}
|
559
662
|
const offerId = promotion[0].offerId || 'EQPROMO'
|
560
|
-
return {
|
561
|
-
priceMap: {[`${offerId}-WRTL`]: product.price.retailSales, [`${offerId}-WWHL`]: product.price.wholesaleSales},
|
663
|
+
return {
|
664
|
+
priceMap: {[`${offerId}-WRTL`]: product.price.retailSales, [`${offerId}-WWHL`]: product.price.wholesaleSales},
|
562
665
|
cvMap: {[`${offerId}-WWHL`]: product.points.wholesale.cv},
|
563
666
|
pvMap: {[`${offerId}-WWHL`]: product.points.wholesale.pv},
|
564
|
-
message: product.salesLabel || promotion[0].message,
|
667
|
+
message: product.salesLabel || promotion[0].message,
|
565
668
|
offerId
|
566
669
|
}
|
567
670
|
}
|