@nuskin/ns-product-lib 2.17.6 → 2.18.0-brw-4218.2
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +4 -3
- package/src/graph-ql/product.js +184 -213
- package/src/productData.js +6 -10
- package/src/graph-ql/mappers/index.js +0 -14
- package/src/graph-ql/mappers/originalPrice.js +0 -24
- package/src/graph-ql/mappers/retailPrice.js +0 -22
- package/src/graph-ql/mappers/retailSubscriptionPrice.js +0 -22
- package/src/graph-ql/mappers/wholesalePrice.js +0 -20
- package/src/graph-ql/mappers/wholesaleSubscriptionPrice.js +0 -22
- package/src/graph-ql/query/getProductById.js +0 -543
- package/src/graph-ql/query/getProductsById.js +0 -547
- package/src/graph-ql/query/index.js +0 -7
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nuskin/ns-product-lib",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.18.0-brw-4218.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": {
|
@@ -22,7 +22,8 @@
|
|
22
22
|
"@nuskin/configuration-sdk": "2.3.2",
|
23
23
|
"@nuskin/ns-common-lib": "1.4.7",
|
24
24
|
"@nuskin/ns-util": "4.5.4",
|
25
|
-
"
|
25
|
+
"@nuskin/product-lib": "2.2.0-brw-4218.1",
|
26
|
+
"axios": "1.6.7",
|
26
27
|
"axios-mock-adapter": "1.21.2",
|
27
28
|
"eslint": "^8.56.0",
|
28
29
|
"eslint-config-google": "^0.14.0",
|
@@ -38,7 +39,7 @@
|
|
38
39
|
"@nuskin/configuration-sdk": "2.x",
|
39
40
|
"@nuskin/ns-common-lib": "1.x",
|
40
41
|
"@nuskin/ns-util": "4.x",
|
41
|
-
"axios": "
|
42
|
+
"axios": "1.6.7"
|
42
43
|
},
|
43
44
|
"dependencies": {
|
44
45
|
"qs": "6.11.0"
|
package/src/graph-ql/product.js
CHANGED
@@ -1,34 +1,7 @@
|
|
1
|
-
const axios = require('axios').default;
|
2
|
-
const { getProductByIdQuery , getProductsByIdQuery } = require('./query');
|
3
1
|
const ProductStatus = require("../models/productStatus");
|
4
2
|
const CustomerTypes = require('./customerTypes');
|
5
3
|
const Product = require("../product");
|
6
|
-
const {
|
7
|
-
mapWholesalePrice,
|
8
|
-
mapRetailPrice,
|
9
|
-
mapRetailSubscriptionPrice,
|
10
|
-
mapWholesaleSubscriptionPrice,
|
11
|
-
mapOriginalPrice
|
12
|
-
} = require('./mappers');
|
13
|
-
|
14
|
-
const defaultPayload = {
|
15
|
-
operationName: "getProduct"
|
16
|
-
};
|
17
|
-
|
18
|
-
/**
|
19
|
-
* graphQl Http request
|
20
|
-
* @param {obj} payload
|
21
|
-
* @returns {Promise}
|
22
|
-
*/
|
23
|
-
async function graphQlHttpRequest(payload, config) {
|
24
|
-
const url = config.graphqlUrl
|
25
|
-
return await axios.request({
|
26
|
-
method: 'post',
|
27
|
-
url: url,
|
28
|
-
data: payload,
|
29
|
-
responseType: 'json'
|
30
|
-
});
|
31
|
-
}
|
4
|
+
const {productLib} = require('@nuskin/product-lib');
|
32
5
|
|
33
6
|
/**
|
34
7
|
* Get product by ID
|
@@ -45,28 +18,20 @@ async function getProduct(id, market, locale, config) {
|
|
45
18
|
count: 0
|
46
19
|
};
|
47
20
|
|
48
|
-
const okta = parseOktaObject(sessionStorage.oktaTokens);
|
49
|
-
|
50
|
-
const payload = {
|
51
|
-
...defaultPayload,
|
52
|
-
query: getProductByIdQuery,
|
53
|
-
variables: {
|
54
|
-
id,
|
55
|
-
market,
|
56
|
-
locale,
|
57
|
-
...(okta !== null && { okta }),
|
58
|
-
quantity: 1 // set default to 1
|
59
|
-
}
|
60
|
-
}
|
21
|
+
const okta = typeof sessionStorage !== 'undefined' ? parseOktaObject(sessionStorage.oktaTokens) : null;
|
61
22
|
|
62
23
|
try {
|
63
|
-
const
|
64
|
-
|
65
|
-
|
66
|
-
|
24
|
+
const data = await productLib.getProduct({
|
25
|
+
fromId: id,
|
26
|
+
market: market,
|
27
|
+
language: locale,
|
28
|
+
env: config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod',
|
29
|
+
okta
|
30
|
+
});
|
31
|
+
if (data && data.data) {
|
67
32
|
//use to get default variant based on requested sku
|
68
33
|
config.sku = id;
|
69
|
-
const product = mapProduct(data.data
|
34
|
+
const product = mapProduct(data.data, market, locale, config);
|
70
35
|
productData.products.push(new Product(product));
|
71
36
|
productData.count = productData.products.length;
|
72
37
|
}
|
@@ -99,30 +64,28 @@ async function getProducts(ids, market, locale, config) {
|
|
99
64
|
count: 0
|
100
65
|
};
|
101
66
|
|
102
|
-
|
103
|
-
|
104
|
-
const payload = {
|
105
|
-
operationName: "getProducts",
|
106
|
-
query: getProductsByIdQuery,
|
107
|
-
variables: {
|
108
|
-
ids,
|
109
|
-
market,
|
110
|
-
language: locale,
|
111
|
-
...(okta !== null && { okta }),
|
112
|
-
quantity: 1 // set default to 1
|
113
|
-
}
|
67
|
+
if (!Array.isArray(ids)) {
|
68
|
+
ids = [ids]
|
114
69
|
}
|
115
70
|
|
71
|
+
const okta = typeof sessionStorage !== 'undefined' ? parseOktaObject(sessionStorage.oktaTokens) : null;
|
72
|
+
|
116
73
|
try {
|
117
|
-
const
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
74
|
+
const data = await productLib.getProductsById(
|
75
|
+
ids, market, locale,
|
76
|
+
null, 1, okta,
|
77
|
+
config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod'
|
78
|
+
);
|
79
|
+
if (data && data.products) {
|
80
|
+
const mappedProducts = mapSkusToProducts(ids,data.products);
|
81
|
+
//use to get default variant based on requested sku
|
82
|
+
mappedProducts.forEach(({sku , product})=>{
|
83
|
+
config.sku = sku;
|
84
|
+
const newProduct = mapProduct(product, market, locale, config);
|
85
|
+
productsData.products.push(new Product(newProduct));
|
86
|
+
});
|
87
|
+
productsData.count = productsData.products.length;
|
88
|
+
}
|
126
89
|
} catch (e) {
|
127
90
|
console.log(`Unable to fetch products details for SKUs ${ids}`);
|
128
91
|
}
|
@@ -143,18 +106,14 @@ async function getProducts(ids, market, locale, config) {
|
|
143
106
|
* @param {any} products
|
144
107
|
*/
|
145
108
|
|
146
|
-
function mapSkusToProducts(skus
|
109
|
+
function mapSkusToProducts(skus, products){
|
147
110
|
const productsData = [];
|
148
|
-
if (products &&
|
149
|
-
products.data &&
|
150
|
-
products.data.productsById &&
|
151
|
-
products.data.productsById.products &&
|
152
|
-
products.data.productsById.products.length) {
|
111
|
+
if (products && products.length) {
|
153
112
|
skus.forEach((sku)=>{
|
154
|
-
const matchedProducts = products.
|
113
|
+
const matchedProducts = products.filter((product)=>{
|
155
114
|
let matched = false;
|
156
115
|
if(product.id) {matched = product.id === sku;}
|
157
|
-
if(product.variants.length){
|
116
|
+
if(product.variants && product.variants.length){
|
158
117
|
product.variants.forEach((variant)=>{
|
159
118
|
matched |= variant.sku === sku;
|
160
119
|
});
|
@@ -170,33 +129,6 @@ function mapSkusToProducts(skus , products){
|
|
170
129
|
|
171
130
|
}
|
172
131
|
|
173
|
-
|
174
|
-
/**
|
175
|
-
* Map product prices
|
176
|
-
* @param {*} product
|
177
|
-
* @param {boolean} isKitBundle
|
178
|
-
* @return {obj} prices
|
179
|
-
*/
|
180
|
-
function mapPrices(product, isKitBundle = false) {
|
181
|
-
const originalPrice = mapOriginalPrice(product, false, isKitBundle) || 0;
|
182
|
-
const retailPrice = mapRetailPrice(product) || 0;
|
183
|
-
const wholesalePrice = mapWholesalePrice(product) || 0;
|
184
|
-
const originalWholeSalePrice = mapOriginalPrice(product, true, isKitBundle) || 0;
|
185
|
-
|
186
|
-
//map subscription (ADR) prices
|
187
|
-
const retailSubscriptionPrice = mapRetailSubscriptionPrice(product) || 0;
|
188
|
-
const wholesaleSubscriptionPrice = mapWholesaleSubscriptionPrice(product) || 0;
|
189
|
-
|
190
|
-
return {
|
191
|
-
originalPrice,
|
192
|
-
originalWholeSalePrice,
|
193
|
-
retailPrice,
|
194
|
-
wholesalePrice,
|
195
|
-
retailSubscriptionPrice,
|
196
|
-
wholesaleSubscriptionPrice
|
197
|
-
}
|
198
|
-
}
|
199
|
-
|
200
132
|
/**
|
201
133
|
*
|
202
134
|
* Map product data to be product card consumable structure *
|
@@ -209,103 +141,87 @@ function mapPrices(product, isKitBundle = false) {
|
|
209
141
|
// eslint-disable-next-line no-unused-vars
|
210
142
|
function mapProduct(product, market, locale, config) {
|
211
143
|
const kitBundleProducts = product.bundle;
|
212
|
-
let variants = product.variants || [];
|
213
|
-
|
214
|
-
|
215
|
-
if (kitBundleProducts) {
|
216
|
-
|
217
|
-
//merge kitBundleProducts and bundle attribute level
|
218
|
-
//since bundle level has totalPrice,availableChannels, etc
|
219
|
-
variants.push({
|
220
|
-
...product,
|
221
|
-
...kitBundleProducts,
|
222
|
-
productDetails: {
|
223
|
-
description: product.description
|
224
|
-
}
|
225
|
-
});
|
226
|
-
}
|
227
|
-
|
228
|
-
|
229
144
|
//serves as parent
|
230
|
-
const defaultVariant = !kitBundleProducts ? product.variants.find(v => v.sku === config.sku) :
|
231
|
-
const productImages = mapProductImages(
|
232
|
-
|
233
|
-
const
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
wholesaleSubscriptionPrice,
|
239
|
-
originalWholeSalePrice
|
240
|
-
} = mapPrices(defaultVariant, !!kitBundleProducts);
|
145
|
+
const defaultVariant = !kitBundleProducts ? product.variants.find(v => v.sku === config.sku) : null
|
146
|
+
const productImages = mapProductImages(product)
|
147
|
+
const kitOrVariant = !kitBundleProducts ? defaultVariant : kitBundleProducts
|
148
|
+
const productOrVariant = !kitBundleProducts ? defaultVariant : product
|
149
|
+
const pricing = kitOrVariant.price
|
150
|
+
const points = kitOrVariant.points
|
151
|
+
const isBackOrdered = kitOrVariant.status.inventory === 'backordered'
|
152
|
+
const promoData = mapPromos(kitOrVariant)
|
241
153
|
|
242
154
|
const productDetail = {
|
243
|
-
"sku": defaultVariant.sku
|
244
|
-
"globalProductID":
|
245
|
-
"title":
|
155
|
+
"sku": !kitBundleProducts ? defaultVariant.sku : product.id,
|
156
|
+
"globalProductID": productOrVariant.globalId && productOrVariant.globalId !== productOrVariant.sku ? productOrVariant.globalId : productOrVariant.id,
|
157
|
+
"title": productOrVariant.title,
|
246
158
|
"country": market,
|
247
159
|
"language": locale,
|
248
|
-
"shortDescr":
|
249
|
-
"longDescr":
|
160
|
+
"shortDescr": productOrVariant.description,
|
161
|
+
"longDescr": (productOrVariant.productDetails || {}).description,
|
250
162
|
"fullImage": productImages.fullImage,
|
251
163
|
"imageAltText": productImages.imageAltText,
|
252
164
|
"thumbnail": productImages.thumbnail,
|
253
|
-
"ingredients":
|
254
|
-
"benefits":
|
255
|
-
"usage":
|
256
|
-
"resources":
|
257
|
-
"availableQuantity":
|
258
|
-
"maxQuantity":
|
165
|
+
"ingredients": productOrVariant.ingredients,
|
166
|
+
"benefits": productOrVariant.benefits,
|
167
|
+
"usage": productOrVariant.usage,
|
168
|
+
"resources": productOrVariant.resources,
|
169
|
+
"availableQuantity": isBackOrdered ? kitOrVariant.backorderQuantity : kitOrVariant.atpQuantity,
|
170
|
+
"maxQuantity": kitOrVariant.maxQuantity,
|
259
171
|
"points": "",
|
260
|
-
"cv":
|
261
|
-
"pv":
|
172
|
+
"cv": points.wholesale ? points.wholesale.cv : 0,
|
173
|
+
"pv": points.wholesale ? points.wholesale.pv : 0,
|
262
174
|
"priceType": "WRTL",
|
263
|
-
"price":
|
175
|
+
"price": pricing.retail,
|
264
176
|
"priceMap": {
|
265
|
-
|
266
|
-
"
|
267
|
-
"
|
268
|
-
"
|
269
|
-
"
|
270
|
-
"
|
271
|
-
"
|
177
|
+
...promoData.priceMap,
|
178
|
+
"ADR": pricing.retailSubscription,
|
179
|
+
"ADW": pricing.wholesaleSubscription,
|
180
|
+
"WRTL": pricing.retail,
|
181
|
+
"WADW-WRTL": pricing.retailSubscription,
|
182
|
+
"WADR": pricing.retailSubscription,
|
183
|
+
"RTL": pricing.retail,
|
184
|
+
"WWHL": pricing.wholesale,
|
185
|
+
"WADW": pricing.wholesaleSubscription,
|
186
|
+
"WHL": pricing.wholesale
|
272
187
|
},
|
273
188
|
"cvMap": {
|
274
|
-
|
275
|
-
"
|
276
|
-
"
|
189
|
+
...promoData.cvMap,
|
190
|
+
"WWHL": points.wholesale ? points.wholesale.cv : 0,
|
191
|
+
"WADW": points.subscription ? points.subscription.cv : 0,
|
192
|
+
"WHL": points.wholesale ? points.wholesale.cv : 0
|
277
193
|
},
|
278
194
|
"pvMap": {
|
279
|
-
|
280
|
-
"
|
281
|
-
"
|
195
|
+
...promoData.pvMap,
|
196
|
+
"WWHL": points.wholesale ? points.wholesale.pv : 0,
|
197
|
+
"WADW": points.subscription ? points.subscription.pv : 0,
|
198
|
+
"WHL": points.wholesale ? points.wholesale.pv : 0
|
282
199
|
},
|
283
|
-
"orderTypes": mapOrderTypes(
|
284
|
-
"custTypes": mapCustomerTypes(
|
285
|
-
"backOrderDate":
|
286
|
-
"size":
|
287
|
-
"status": mapProductStatus(
|
200
|
+
"orderTypes": mapOrderTypes(kitOrVariant.availableChannels, kitOrVariant.purchaseTypes),
|
201
|
+
"custTypes": mapCustomerTypes(kitOrVariant.customerTypes),
|
202
|
+
"backOrderDate": kitOrVariant.backorderedAvailableDate,
|
203
|
+
"size": productOrVariant.size,
|
204
|
+
"status": mapProductStatus(kitOrVariant.status.status),
|
288
205
|
"variantType": "Other",
|
289
206
|
"variantDropdownLabel": product.variantSelectLabel || '',
|
290
207
|
"variantDropdownPlaceholder": "Select Type",
|
291
|
-
"variantsLabel":
|
208
|
+
"variantsLabel": productOrVariant.variantLabel || '',
|
292
209
|
"groupOffer": false,
|
293
210
|
"personalOffer": false,
|
294
211
|
"savedEventName": '',
|
295
|
-
"salesLabel":
|
296
|
-
"eventName":
|
212
|
+
"salesLabel": promoData.message || '',
|
213
|
+
"eventName": promoData.offerId || '',
|
297
214
|
"sizeWeight": '',
|
298
215
|
"nettoWeight": "",
|
299
216
|
"searchScore": 0,
|
300
|
-
"isExclusive":
|
217
|
+
"isExclusive": kitOrVariant.isExclusive || false,
|
301
218
|
"equinoxProductId": product.id,
|
302
|
-
"inventory":
|
219
|
+
"inventory": isBackOrdered ? 'BACKORDER' : 'IN STOCK',
|
303
220
|
"properties": {
|
304
|
-
isBackOrdered:
|
305
|
-
inventoryStatus:
|
306
|
-
productStatus: mapProductStatus(
|
221
|
+
isBackOrdered: isBackOrdered,
|
222
|
+
inventoryStatus: isBackOrdered ? 'BACKORDER' : 'IN STOCK',
|
223
|
+
productStatus: mapProductStatus(kitOrVariant.status.status)
|
307
224
|
}
|
308
|
-
|
309
225
|
}
|
310
226
|
|
311
227
|
//map only if it is normal product
|
@@ -350,13 +266,10 @@ function mapVariants(product) {
|
|
350
266
|
const sku = variant.sku || variant.id;
|
351
267
|
|
352
268
|
const productImages = mapProductImages(variant);
|
353
|
-
const
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
retailSubscriptionPrice,
|
358
|
-
wholesaleSubscriptionPrice
|
359
|
-
} = mapPrices(variant);
|
269
|
+
const pricing = variant.price
|
270
|
+
const points = variant.points
|
271
|
+
const isBackOrdered = variant.status.inventory === 'backordered'
|
272
|
+
const promoData = mapPromos(variant)
|
360
273
|
|
361
274
|
variants[sku] = {
|
362
275
|
"sku": sku,
|
@@ -374,28 +287,33 @@ function mapVariants(product) {
|
|
374
287
|
"availableQuantity": variant.availableQuantity,
|
375
288
|
"maxQuantity": variant.maxQuantity,
|
376
289
|
"points": "",
|
377
|
-
"cv":
|
378
|
-
"pv":
|
290
|
+
"cv": points.wholesale ? points.wholesale.cv : 0,
|
291
|
+
"pv": points.wholesale ? points.wholesale.pv : 0,
|
379
292
|
"priceType": "WRTL",
|
380
|
-
"price":
|
293
|
+
"price": pricing.retail,
|
381
294
|
"priceMap": {
|
382
|
-
|
383
|
-
"
|
384
|
-
"
|
385
|
-
"
|
386
|
-
"
|
387
|
-
"
|
388
|
-
"
|
295
|
+
...promoData.priceMap,
|
296
|
+
"ADR": pricing.retailSubscription,
|
297
|
+
"ADW": pricing.wholesaleSubscription,
|
298
|
+
"WRTL": pricing.retail,
|
299
|
+
"WADW-WRTL": pricing.retailSubscription,
|
300
|
+
"WADR": pricing.retailSubscription,
|
301
|
+
"RTL": pricing.retail,
|
302
|
+
"WWHL": pricing.wholesale,
|
303
|
+
"WADW": pricing.wholesaleSubscription,
|
304
|
+
"WHL": pricing.wholesale
|
389
305
|
},
|
390
306
|
"cvMap": {
|
391
|
-
|
392
|
-
"
|
393
|
-
"
|
307
|
+
...promoData.cvMap,
|
308
|
+
"WWHL": points.wholesale ? points.wholesale.cv : 0,
|
309
|
+
"WADW": points.subscription ? points.subscription.cv : 0,
|
310
|
+
"WHL": points.wholesale ? points.wholesale.cv : 0
|
394
311
|
},
|
395
312
|
"pvMap": {
|
396
|
-
|
397
|
-
"
|
398
|
-
"
|
313
|
+
...promoData.pvMap,
|
314
|
+
"WWHL": points.wholesale ? points.wholesale.pv : 0,
|
315
|
+
"WADW": points.subscription ? points.subscription.pv : 0,
|
316
|
+
"WHL": points.wholesale ? points.wholesale.pv : 0
|
399
317
|
},
|
400
318
|
"orderTypes": mapOrderTypes(variant.availableChannels, variant.purchaseTypes),
|
401
319
|
"custTypes": mapCustomerTypes(variant.customerTypes),
|
@@ -417,10 +335,10 @@ function mapVariants(product) {
|
|
417
335
|
"searchScore": 0,
|
418
336
|
"isExclusive": variant.isExclusive || false,
|
419
337
|
"equinoxProductId": product.id,
|
420
|
-
"inventory":
|
338
|
+
"inventory": isBackOrdered ? 'BACKORDER' : 'IN STOCK',
|
421
339
|
"properties": {
|
422
|
-
isBackOrdered:
|
423
|
-
inventoryStatus:
|
340
|
+
isBackOrdered: isBackOrdered,
|
341
|
+
inventoryStatus: isBackOrdered ? 'BACKORDER' : 'IN STOCK',
|
424
342
|
productStatus: mapProductStatus(variant.status.status)
|
425
343
|
}
|
426
344
|
}
|
@@ -438,7 +356,7 @@ function mapChildSKU(kitBundleProducts) {
|
|
438
356
|
if (!kitBundleProducts || !kitBundleProducts.kitProducts) {
|
439
357
|
return [];
|
440
358
|
}
|
441
|
-
const personalOffer = sessionStorage.getItem('personalOffer') ? JSON.parse(sessionStorage.getItem('personalOffer')) : false
|
359
|
+
const personalOffer = typeof sessionStorage !== 'undefined' && sessionStorage.getItem('personalOffer') ? JSON.parse(sessionStorage.getItem('personalOffer')) : false
|
442
360
|
return kitBundleProducts.kitProducts.map((kitProduct) => {
|
443
361
|
const { product } = kitProduct;
|
444
362
|
if (product.variants.length > 1 && typeof personalOffer === 'object') {
|
@@ -451,9 +369,9 @@ function mapChildSKU(kitBundleProducts) {
|
|
451
369
|
// eslint-disable-next-line max-len
|
452
370
|
availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
|
453
371
|
inventory: {
|
454
|
-
atpQty: variant.
|
455
|
-
backOrdered: variant.status.
|
456
|
-
backOrderedQty: variant.
|
372
|
+
atpQty: variant.atpQuantity,
|
373
|
+
backOrdered: variant.status.inventory === 'backordered',
|
374
|
+
backOrderedQty: variant.backorderQuantity
|
457
375
|
}
|
458
376
|
}
|
459
377
|
})
|
@@ -466,9 +384,9 @@ function mapChildSKU(kitBundleProducts) {
|
|
466
384
|
skuQuantity: kitProduct.quantity,
|
467
385
|
availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
|
468
386
|
inventory: {
|
469
|
-
atpQty: defaultVariant.
|
470
|
-
backOrdered: defaultVariant.status.
|
471
|
-
backOrderedQty: defaultVariant.
|
387
|
+
atpQty: defaultVariant.atpQuantity,
|
388
|
+
backOrdered: defaultVariant.status.inventory === 'backordered',
|
389
|
+
backOrderedQty: defaultVariant.backorderQuantity
|
472
390
|
}
|
473
391
|
}
|
474
392
|
}
|
@@ -526,6 +444,12 @@ function mapProductImages(product) {
|
|
526
444
|
productImages.fullImage = product.productImages[0].url || '';
|
527
445
|
productImages.imageAltText = product.productImages[0].alt || '';
|
528
446
|
productImages.thumbnail = product.productImages[0].thumbnail || '';
|
447
|
+
} else if (product.variants && product.variants.length) {
|
448
|
+
if (product.variants[0].productImages && product.variants[0].productImages.length) {
|
449
|
+
productImages.fullImage = product.variants[0].productImages[0].url || '';
|
450
|
+
productImages.imageAltText = product.variants[0].productImages[0].alt || '';
|
451
|
+
productImages.thumbnail = product.variants[0].productImages[0].thumbnail || '';
|
452
|
+
}
|
529
453
|
}
|
530
454
|
|
531
455
|
return productImages;
|
@@ -576,9 +500,16 @@ function mapOrderTypes(availableChannels, purchaseTypes) {
|
|
576
500
|
orderTypes.web = true
|
577
501
|
orderTypes.order = true
|
578
502
|
}
|
503
|
+
if (purchaseTypes && !purchaseTypes.buyOnce) {
|
504
|
+
orderTypes.web = false
|
505
|
+
orderTypes.order = false
|
506
|
+
}
|
579
507
|
if (purchaseTypes && purchaseTypes.subscription) {
|
580
508
|
orderTypes.adr = true
|
581
509
|
}
|
510
|
+
if (purchaseTypes && !purchaseTypes.subscription) {
|
511
|
+
orderTypes.adr = false
|
512
|
+
}
|
582
513
|
|
583
514
|
return orderTypes;
|
584
515
|
}
|
@@ -611,19 +542,59 @@ function mapProductStatus(status) {
|
|
611
542
|
newStatus = ProductStatus.NotReleasedForSale;
|
612
543
|
break;
|
613
544
|
}
|
614
|
-
|
615
545
|
return newStatus;
|
616
546
|
}
|
617
547
|
|
618
|
-
function mapPromos(product
|
619
|
-
if (
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
548
|
+
function mapPromos(product) {
|
549
|
+
if ((product.price.retailSales !== null && product.price.retailSales >= 0) || (product.price.wholesaleSales !== null && product.price.wholesaleSales >= 0)) {
|
550
|
+
if (product.pricingJson) {
|
551
|
+
const parsedPricing = JSON.parse(product.pricingJson)
|
552
|
+
const promotion = parsedPricing.promotion
|
553
|
+
if (promotion && promotion.length) {
|
554
|
+
const offerId = promotion[0].offerId || 'EQPROMO'
|
555
|
+
return {
|
556
|
+
priceMap: {[`${offerId}-WRTL`]: product.price.retailSales, [`${offerId}-WWHL`]: product.price.wholesaleSales},
|
557
|
+
cvMap: {[`${offerId}-WWHL`]: product.points.wholesale.cv},
|
558
|
+
pvMap: {[`${offerId}-WWHL`]: product.points.wholesale.pv},
|
559
|
+
message: product.salesLabel || promotion[0].message,
|
560
|
+
offerId
|
561
|
+
}
|
562
|
+
}
|
563
|
+
if (parsedPricing.retail) {
|
564
|
+
const filter = ['adr', 'order', 'webAdr', 'webOrder']
|
565
|
+
const priceMap = {}, cvMap = {}, pvMap = {}
|
566
|
+
const retailActiveEvents = Object.fromEntries(Object.entries(parsedPricing.retail).filter(([k]) => !filter.includes(k)));
|
567
|
+
const wholesaleActiveEvents = Object.fromEntries(Object.entries(parsedPricing.wholesale).filter(([k]) => !filter.includes(k)));
|
568
|
+
let offerId = null
|
569
|
+
for (const key in retailActiveEvents) {
|
570
|
+
if (Object.hasOwnProperty.call(retailActiveEvents, key)) {
|
571
|
+
priceMap[key+'-WRTL'] = retailActiveEvents[key].price;
|
572
|
+
offerId = offerId || key;
|
573
|
+
}
|
574
|
+
}
|
575
|
+
for (const key in wholesaleActiveEvents) {
|
576
|
+
if (Object.hasOwnProperty.call(wholesaleActiveEvents, key)) {
|
577
|
+
priceMap[key+'-WWHL'] = wholesaleActiveEvents[key].price;
|
578
|
+
cvMap[key+'-WWHL'] = wholesaleActiveEvents[key].cv;
|
579
|
+
pvMap[key+'-WWHL'] = wholesaleActiveEvents[key].pv;
|
580
|
+
offerId = offerId || key;
|
581
|
+
}
|
582
|
+
}
|
583
|
+
return { priceMap, cvMap, pvMap, message: product.salesLabel, offerId }
|
584
|
+
}
|
585
|
+
|
586
|
+
}
|
587
|
+
return { message: product.salesLabel, offerId: null, priceMap: {}, cvMap: {}, pvMap: {} }
|
626
588
|
}
|
589
|
+
return {message: null, offerId: null}
|
590
|
+
// if (isKitBundle) {
|
591
|
+
// const { pricingJson } = product
|
592
|
+
// const parsedPricing = JSON.parse(pricingJson)
|
593
|
+
// const promotion = parsedPricing.promotion
|
594
|
+
// return (promotion && promotion.length >= 1) ? { message: promotion[0].message, offerId: promotion[0].offerId } : { message: '', offerId: '' }
|
595
|
+
// } else {
|
596
|
+
// return { message: product.salesLabel || product.salesText, offerId: product.salesLabel || product.salesText }
|
597
|
+
// }
|
627
598
|
|
628
599
|
}
|
629
600
|
|
package/src/productData.js
CHANGED
@@ -23,17 +23,13 @@ const ProductData = {
|
|
23
23
|
getProductData: async function (skus, locale, market) {
|
24
24
|
const localeMarket = `${locale}_${market}`;
|
25
25
|
|
26
|
+
// USE THESE TWO LINES FOR LOCAL TESTING INSTEAD OF const config alone
|
27
|
+
// let runConfig = { country: market, language: locale, environment: 'test', clientId: '66408e5bca6b4a59b2c7fc62b8c00a9f' };
|
28
|
+
// const config = (await getConfiguration(['Equinox_Markets'], runConfig)).Equinox_Markets;
|
26
29
|
const config = (await getConfiguration(['Equinox_Markets'])).Equinox_Markets;
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
await this.getProductFromEquinox(skus, localeMarket, config)
|
31
|
-
} else {
|
32
|
-
return (config.MySite_graphql_active_list.includes(market)) ?
|
33
|
-
await getProducts(skus, market, locale, config) :
|
34
|
-
await this.getProductFromLegacy(skus, localeMarket);
|
35
|
-
}
|
36
|
-
|
30
|
+
return (config.MySite_graphql_active_list.includes(market)) ?
|
31
|
+
await getProducts(skus, market, locale, config) :
|
32
|
+
await this.getProductFromLegacy(skus, localeMarket);
|
37
33
|
},
|
38
34
|
|
39
35
|
getProductFromEquinox: async function (skus, locale, config) {
|
@@ -1,14 +0,0 @@
|
|
1
|
-
|
2
|
-
const wholesalePrice = require('./wholesalePrice');
|
3
|
-
const retailPrice = require('./retailPrice');
|
4
|
-
const retailSubscriptionPrice = require('./retailSubscriptionPrice')
|
5
|
-
const wholesaleSubscriptionPrice = require('./wholesaleSubscriptionPrice')
|
6
|
-
const originalPrice = require('./originalPrice');
|
7
|
-
|
8
|
-
module.exports = {
|
9
|
-
mapWholesalePrice: wholesalePrice,
|
10
|
-
mapRetailPrice: retailPrice,
|
11
|
-
mapRetailSubscriptionPrice: retailSubscriptionPrice,
|
12
|
-
mapWholesaleSubscriptionPrice: wholesaleSubscriptionPrice,
|
13
|
-
mapOriginalPrice : originalPrice
|
14
|
-
}
|
@@ -1,24 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Map original price (set to retail)
|
5
|
-
* use original price if product type is equal to kit/bundle
|
6
|
-
* @param {obj} product
|
7
|
-
* @param {boolean} isWholesale default === false
|
8
|
-
* @param {boolean} isBundleKit default === false
|
9
|
-
* @return {number} retailPrice
|
10
|
-
*/
|
11
|
-
function originalPrice(product, isWholesale = false, isBundleKit = false) {
|
12
|
-
const { price, totalPrice } = product;
|
13
|
-
const productPrice = price ? price : totalPrice;
|
14
|
-
|
15
|
-
if (isBundleKit) {
|
16
|
-
|
17
|
-
return isWholesale ? productPrice.wholesaleOriginal : productPrice.retailOriginal;
|
18
|
-
}
|
19
|
-
|
20
|
-
return isWholesale ? productPrice.wholesale : productPrice.retail;
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
module.exports = originalPrice;
|
@@ -1,22 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Map retail price
|
5
|
-
* Map retailSales if it has sales/promotions
|
6
|
-
* @param {obj} product
|
7
|
-
* @return {number} retailPrice
|
8
|
-
*/
|
9
|
-
function retailPrice(product) {
|
10
|
-
const { price, totalPrice } = product;
|
11
|
-
const productPrice = price ? price : totalPrice;
|
12
|
-
|
13
|
-
if (productPrice.retailSales) {
|
14
|
-
|
15
|
-
return productPrice.retailSales;
|
16
|
-
}
|
17
|
-
|
18
|
-
return productPrice.retail;
|
19
|
-
|
20
|
-
}
|
21
|
-
|
22
|
-
module.exports = retailPrice;
|