@nuskin/ns-product-lib 2.17.2 → 2.18.0-brw-4218.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.17.2",
3
+ "version": "2.18.0-brw-4218.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": {
@@ -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
- "axios": ">=1.6.5",
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": ">=1.6.5"
42
+ "axios": "1.6.7"
42
43
  },
43
44
  "dependencies": {
44
45
  "qs": "6.11.0"
@@ -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,21 @@ 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 { data } = await graphQlHttpRequest(payload, config);
64
-
65
- if (data && data.data && data.data.productById) {
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
+ });
66
31
 
32
+ if (data && data.data) {
67
33
  //use to get default variant based on requested sku
68
34
  config.sku = id;
69
- const product = mapProduct(data.data.productById, market, locale, config);
35
+ const product = mapProduct(data.data, market, locale, config);
70
36
  productData.products.push(new Product(product));
71
37
  productData.count = productData.products.length;
72
38
  }
@@ -99,30 +65,24 @@ async function getProducts(ids, market, locale, config) {
99
65
  count: 0
100
66
  };
101
67
 
102
- const okta = parseOktaObject(sessionStorage.oktaTokens);
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
- }
114
- }
68
+ const okta = typeof sessionStorage !== 'undefined' ? parseOktaObject(sessionStorage.oktaTokens) : null;
115
69
 
116
70
  try {
117
- const { data } = await graphQlHttpRequest(payload, config);
118
- const mappedProducts = mapSkusToProducts(ids,data);
119
- //use to get default variant based on requested sku
120
- mappedProducts.forEach(({sku , product})=>{
121
- config.sku = sku;
122
- const newProduct = mapProduct(product, market, locale, config);
123
- productsData.products.push(new Product(newProduct));
124
- });
125
- productsData.count = productsData.products.length;
71
+ const data = await productLib.getProductsById(
72
+ ids, market, locale,
73
+ null, 1, okta,
74
+ config.graphqlUrl.includes('test') ? 'test' : config.graphqlUrl.includes('dev') ? 'dev' : 'prod'
75
+ );
76
+ if (data && data.products) {
77
+ const mappedProducts = mapSkusToProducts(ids,data.products);
78
+ //use to get default variant based on requested sku
79
+ mappedProducts.forEach(({sku , product})=>{
80
+ config.sku = sku;
81
+ const newProduct = mapProduct(product, market, locale, config);
82
+ productsData.products.push(new Product(newProduct));
83
+ });
84
+ productsData.count = productsData.products.length;
85
+ }
126
86
  } catch (e) {
127
87
  console.log(`Unable to fetch products details for SKUs ${ids}`);
128
88
  }
@@ -143,15 +103,11 @@ async function getProducts(ids, market, locale, config) {
143
103
  * @param {any} products
144
104
  */
145
105
 
146
- function mapSkusToProducts(skus , products){
106
+ function mapSkusToProducts(skus, products){
147
107
  const productsData = [];
148
- if (products &&
149
- products.data &&
150
- products.data.productsById &&
151
- products.data.productsById.products &&
152
- products.data.productsById.products.length) {
108
+ if (products && products.length) {
153
109
  skus.forEach((sku)=>{
154
- const matchedProducts = products.data.productsById.products.filter((product)=>{
110
+ const matchedProducts = products.filter((product)=>{
155
111
  let matched = false;
156
112
  if(product.id) {matched = product.id === sku;}
157
113
  if(product.variants.length){
@@ -170,33 +126,6 @@ function mapSkusToProducts(skus , products){
170
126
 
171
127
  }
172
128
 
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
129
  /**
201
130
  *
202
131
  * Map product data to be product card consumable structure *
@@ -209,103 +138,87 @@ function mapPrices(product, isKitBundle = false) {
209
138
  // eslint-disable-next-line no-unused-vars
210
139
  function mapProduct(product, market, locale, config) {
211
140
  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
141
  //serves as parent
230
- const defaultVariant = !kitBundleProducts ? product.variants.find(v => v.sku === config.sku) : variants[0];
231
- const productImages = mapProductImages(defaultVariant);
232
-
233
- const {
234
- originalPrice,
235
- retailPrice,
236
- wholesalePrice,
237
- retailSubscriptionPrice,
238
- wholesaleSubscriptionPrice,
239
- originalWholeSalePrice
240
- } = mapPrices(defaultVariant, !!kitBundleProducts);
142
+ const defaultVariant = !kitBundleProducts ? product.variants.find(v => v.sku === config.sku) : null
143
+ const productImages = mapProductImages(product)
144
+ const kitOrVariant = !kitBundleProducts ? defaultVariant : kitBundleProducts
145
+ const productOrVariant = !kitBundleProducts ? defaultVariant : product
146
+ const pricing = kitOrVariant.price
147
+ const points = kitOrVariant.points
148
+ const isBackOrdered = kitOrVariant.status.inventory === 'backordered'
149
+ const promoData = mapPromos(kitOrVariant)
241
150
 
242
151
  const productDetail = {
243
- "sku": defaultVariant.sku || product.id,
244
- "globalProductID": product.id,
245
- "title": defaultVariant.title,
152
+ "sku": !kitBundleProducts ? defaultVariant.sku : product.id,
153
+ "globalProductID": productOrVariant.globalId && productOrVariant.globalId !== productOrVariant.sku ? productOrVariant.globalId : productOrVariant.id,
154
+ "title": productOrVariant.title,
246
155
  "country": market,
247
156
  "language": locale,
248
- "shortDescr": defaultVariant.description,
249
- "longDescr": defaultVariant.productDetails.description,
157
+ "shortDescr": productOrVariant.description,
158
+ "longDescr": (productOrVariant.productDetails || {}).description,
250
159
  "fullImage": productImages.fullImage,
251
160
  "imageAltText": productImages.imageAltText,
252
161
  "thumbnail": productImages.thumbnail,
253
- "ingredients": defaultVariant.ingredients,
254
- "benefits": defaultVariant.benefits,
255
- "usage": defaultVariant.usage,
256
- "resources": defaultVariant.resoruces,
257
- "availableQuantity": defaultVariant.availableQuantity,
258
- "maxQuantity": defaultVariant.maxQuantity,
162
+ "ingredients": productOrVariant.ingredients,
163
+ "benefits": productOrVariant.benefits,
164
+ "usage": productOrVariant.usage,
165
+ "resources": productOrVariant.resources,
166
+ "availableQuantity": isBackOrdered ? kitOrVariant.backorderQuantity : kitOrVariant.atpQuantity,
167
+ "maxQuantity": kitOrVariant.maxQuantity,
259
168
  "points": "",
260
- "cv": (defaultVariant.points) ? defaultVariant.points.wholesale.cv : 0,
261
- "pv": (defaultVariant.points) ? defaultVariant.points.wholesale.pv : 0,
169
+ "cv": points.wholesale ? points.wholesale.cv : 0,
170
+ "pv": points.wholesale ? points.wholesale.pv : 0,
262
171
  "priceType": "WRTL",
263
- "price": originalPrice,
172
+ "price": pricing.retail,
264
173
  "priceMap": {
265
- "WRTL": retailPrice,
266
- "WADW-WRTL": retailSubscriptionPrice,
267
- "WADR": retailSubscriptionPrice,
268
- "RTL": originalPrice,
269
- "WWHL": wholesalePrice,
270
- "WADW": wholesaleSubscriptionPrice,
271
- "WHL": originalWholeSalePrice
174
+ ...promoData.priceMap,
175
+ "ADR": pricing.retailSubscription,
176
+ "ADW": pricing.wholesaleSubscription,
177
+ "WRTL": pricing.retail,
178
+ "WADW-WRTL": pricing.retailSubscription,
179
+ "WADR": pricing.retailSubscription,
180
+ "RTL": pricing.retail,
181
+ "WWHL": pricing.wholesale,
182
+ "WADW": pricing.wholesaleSubscription,
183
+ "WHL": pricing.wholesale
272
184
  },
273
185
  "cvMap": {
274
- "WWHL": (defaultVariant.points) ? defaultVariant.points.wholesale.cv : 0,
275
- "WADW": (defaultVariant.points) ? defaultVariant.points.subscription.cv : 0,
276
- "WHL": (defaultVariant.points) ? defaultVariant.points.wholesale.cv : 0
186
+ ...promoData.cvMap,
187
+ "WWHL": points.wholesale ? points.wholesale.cv : 0,
188
+ "WADW": points.subscription ? points.subscription.cv : 0,
189
+ "WHL": points.wholesale ? points.wholesale.cv : 0
277
190
  },
278
191
  "pvMap": {
279
- "WWHL": (defaultVariant.points) ? defaultVariant.points.wholesale.pv : 0,
280
- "WADW": (defaultVariant.points) ? defaultVariant.points.subscription.pv : 0,
281
- "WHL": (defaultVariant.points) ? defaultVariant.points.wholesale.pv : 0
192
+ ...promoData.pvMap,
193
+ "WWHL": points.wholesale ? points.wholesale.pv : 0,
194
+ "WADW": points.subscription ? points.subscription.pv : 0,
195
+ "WHL": points.wholesale ? points.wholesale.pv : 0
282
196
  },
283
- "orderTypes": mapOrderTypes(defaultVariant.availableChannels, defaultVariant.purchaseTypes),
284
- "custTypes": mapCustomerTypes(defaultVariant.customerTypes),
285
- "backOrderDate": defaultVariant.status.backorderedAvailableDate,
286
- "size": defaultVariant.size,
287
- "status": mapProductStatus(defaultVariant.status.status),
197
+ "orderTypes": mapOrderTypes(kitOrVariant.availableChannels, kitOrVariant.purchaseTypes),
198
+ "custTypes": mapCustomerTypes(kitOrVariant.customerTypes),
199
+ "backOrderDate": kitOrVariant.backorderedAvailableDate,
200
+ "size": productOrVariant.size,
201
+ "status": mapProductStatus(kitOrVariant.status.status),
288
202
  "variantType": "Other",
289
203
  "variantDropdownLabel": product.variantSelectLabel || '',
290
204
  "variantDropdownPlaceholder": "Select Type",
291
- "variantsLabel": defaultVariant.variantLabel || '',
205
+ "variantsLabel": productOrVariant.variantLabel || '',
292
206
  "groupOffer": false,
293
207
  "personalOffer": false,
294
208
  "savedEventName": '',
295
- "salesLabel": mapPromos(defaultVariant, !!kitBundleProducts).message || '',
296
- "eventName": mapPromos(defaultVariant, !!kitBundleProducts).offerId || '',
209
+ "salesLabel": promoData.message || '',
210
+ "eventName": promoData.offerId || '',
297
211
  "sizeWeight": '',
298
212
  "nettoWeight": "",
299
213
  "searchScore": 0,
300
- "isExclusive": defaultVariant.isExclusive || false,
214
+ "isExclusive": kitOrVariant.isExclusive || false,
301
215
  "equinoxProductId": product.id,
302
- "inventory": defaultVariant.status.isBackordered ? 'BACKORDER' : 'IN STOCK',
216
+ "inventory": isBackOrdered ? 'BACKORDER' : 'IN STOCK',
303
217
  "properties": {
304
- isBackOrdered: defaultVariant.status.isBackordered,
305
- inventoryStatus: defaultVariant.status.isBackordered ? 'BACKORDER' : 'IN STOCK',
306
- productStatus: mapProductStatus(defaultVariant.status.status)
218
+ isBackOrdered: isBackOrdered,
219
+ inventoryStatus: isBackOrdered ? 'BACKORDER' : 'IN STOCK',
220
+ productStatus: mapProductStatus(kitOrVariant.status.status)
307
221
  }
308
-
309
222
  }
310
223
 
311
224
  //map only if it is normal product
@@ -350,13 +263,10 @@ function mapVariants(product) {
350
263
  const sku = variant.sku || variant.id;
351
264
 
352
265
  const productImages = mapProductImages(variant);
353
- const {
354
- originalPrice,
355
- retailPrice,
356
- wholesalePrice,
357
- retailSubscriptionPrice,
358
- wholesaleSubscriptionPrice
359
- } = mapPrices(variant);
266
+ const pricing = variant.price
267
+ const points = variant.points
268
+ const isBackOrdered = variant.status.inventory === 'backordered'
269
+ const promoData = mapPromos(variant)
360
270
 
361
271
  variants[sku] = {
362
272
  "sku": sku,
@@ -374,28 +284,33 @@ function mapVariants(product) {
374
284
  "availableQuantity": variant.availableQuantity,
375
285
  "maxQuantity": variant.maxQuantity,
376
286
  "points": "",
377
- "cv": (variant.points) ? variant.points.wholesale.cv : 0,
378
- "pv": (variant.points) ? variant.points.wholesale.pv : 0,
287
+ "cv": points.wholesale ? points.wholesale.cv : 0,
288
+ "pv": points.wholesale ? points.wholesale.pv : 0,
379
289
  "priceType": "WRTL",
380
- "price": originalPrice,
290
+ "price": pricing.retail,
381
291
  "priceMap": {
382
- "WRTL": retailPrice,
383
- "WADW-WRTL": retailSubscriptionPrice,
384
- "WADR": retailSubscriptionPrice,
385
- "RTL": retailPrice,
386
- "WWHL": wholesalePrice,
387
- "WADW": wholesaleSubscriptionPrice,
388
- "WHL": wholesalePrice
292
+ ...promoData.priceMap,
293
+ "ADR": pricing.retailSubscription,
294
+ "ADW": pricing.wholesaleSubscription,
295
+ "WRTL": pricing.retail,
296
+ "WADW-WRTL": pricing.retailSubscription,
297
+ "WADR": pricing.retailSubscription,
298
+ "RTL": pricing.retail,
299
+ "WWHL": pricing.wholesale,
300
+ "WADW": pricing.wholesaleSubscription,
301
+ "WHL": pricing.wholesale
389
302
  },
390
303
  "cvMap": {
391
- "WWHL": (variant.points) ? variant.points.wholesale.cv : 0,
392
- "WADW": (variant.points) ? variant.points.subscription.cv : 0,
393
- "WHL": (variant.points) ? variant.points.wholesale.cv : 0
304
+ ...promoData.cvMap,
305
+ "WWHL": points.wholesale ? points.wholesale.cv : 0,
306
+ "WADW": points.subscription ? points.subscription.cv : 0,
307
+ "WHL": points.wholesale ? points.wholesale.cv : 0
394
308
  },
395
309
  "pvMap": {
396
- "WWHL": (variant.points) ? variant.points.wholesale.pv : 0,
397
- "WADW": (variant.points) ? variant.points.subscription.pv : 0,
398
- "WHL": (variant.points) ? variant.points.wholesale.pv : 0
310
+ ...promoData.pvMap,
311
+ "WWHL": points.wholesale ? points.wholesale.pv : 0,
312
+ "WADW": points.subscription ? points.subscription.pv : 0,
313
+ "WHL": points.wholesale ? points.wholesale.pv : 0
399
314
  },
400
315
  "orderTypes": mapOrderTypes(variant.availableChannels, variant.purchaseTypes),
401
316
  "custTypes": mapCustomerTypes(variant.customerTypes),
@@ -417,10 +332,10 @@ function mapVariants(product) {
417
332
  "searchScore": 0,
418
333
  "isExclusive": variant.isExclusive || false,
419
334
  "equinoxProductId": product.id,
420
- "inventory": variant.status.isBackordered ? 'BACKORDER' : 'IN STOCK', //@todo deprecate this since we can set properties.isBackOrdered
335
+ "inventory": isBackOrdered ? 'BACKORDER' : 'IN STOCK',
421
336
  "properties": {
422
- isBackOrdered: variant.status.isBackordered,
423
- inventoryStatus: variant.status.isBackordered ? 'BACKORDER' : 'IN STOCK',
337
+ isBackOrdered: isBackOrdered,
338
+ inventoryStatus: isBackOrdered ? 'BACKORDER' : 'IN STOCK',
424
339
  productStatus: mapProductStatus(variant.status.status)
425
340
  }
426
341
  }
@@ -449,9 +364,9 @@ function mapChildSKU(kitBundleProducts) {
449
364
  skuQuantity: kitProduct.quantity,
450
365
  availableChannels: Array.isArray(kitBundleProducts.availableChannels) ? kitBundleProducts.availableChannels.join(',') : kitBundleProducts.availableChannels,
451
366
  inventory: {
452
- atpQty: defaultVariant.availableQuantity,
453
- backOrdered: defaultVariant.status.isBackordered,
454
- backOrderedQty: defaultVariant.availableQuantity
367
+ atpQty: defaultVariant.atpQuantity,
368
+ backOrdered: defaultVariant.status.inventory === 'backordered',
369
+ backOrderedQty: defaultVariant.backorderQuantity
455
370
  }
456
371
  }
457
372
  });
@@ -508,6 +423,12 @@ function mapProductImages(product) {
508
423
  productImages.fullImage = product.productImages[0].url || '';
509
424
  productImages.imageAltText = product.productImages[0].alt || '';
510
425
  productImages.thumbnail = product.productImages[0].thumbnail || '';
426
+ } else if (product.variants && product.variants.length) {
427
+ if (product.variants[0].productImages && product.variants[0].productImages.length) {
428
+ productImages.fullImage = product.variants[0].productImages[0].url || '';
429
+ productImages.imageAltText = product.variants[0].productImages[0].alt || '';
430
+ productImages.thumbnail = product.variants[0].productImages[0].thumbnail || '';
431
+ }
511
432
  }
512
433
 
513
434
  return productImages;
@@ -597,15 +518,56 @@ function mapProductStatus(status) {
597
518
  return newStatus;
598
519
  }
599
520
 
600
- function mapPromos(product, isKitBundle = false) {
601
- if (isKitBundle) {
602
- const { pricingJson } = product
603
- const parsedPricing = JSON.parse(pricingJson)
604
- const promotion = parsedPricing.promotion
605
- return (promotion && promotion.length >= 1) ? { message: promotion[0].message, offerId: promotion[0].offerId } : { message: '', offerId: '' }
606
- } else {
607
- return { message: product.salesLabel || product.salesText, offerId: product.salesLabel || product.salesText }
521
+ function mapPromos(product) {
522
+ if ((product.price.retailSales !== null && product.price.retailSales >= 0) || (product.price.wholesaleSales !== null && product.price.wholesaleSales >= 0)) {
523
+ if (product.pricingJson) {
524
+ const parsedPricing = JSON.parse(product.pricingJson)
525
+ const promotion = parsedPricing.promotion
526
+ if (promotion && promotion.length) {
527
+ const offerId = promotion[0].offerId || 'EQPROMO'
528
+ return {
529
+ priceMap: {[`${offerId}-WRTL`]: product.price.retailSales, [`${offerId}-WWHL`]: product.price.wholesaleSales},
530
+ cvMap: {[`${offerId}-WWHL`]: product.points.wholesale.cv},
531
+ pvMap: {[`${offerId}-WWHL`]: product.points.wholesale.pv},
532
+ message: product.salesLabel || promotion[0].message,
533
+ offerId
534
+ }
535
+ }
536
+ if (parsedPricing.retail) {
537
+ const filter = ['adr', 'order', 'webAdr', 'webOrder']
538
+ const priceMap = {}, cvMap = {}, pvMap = {}
539
+ const retailActiveEvents = Object.fromEntries(Object.entries(parsedPricing.retail).filter(([k]) => !filter.includes(k)));
540
+ const wholesaleActiveEvents = Object.fromEntries(Object.entries(parsedPricing.wholesale).filter(([k]) => !filter.includes(k)));
541
+ let offerId = null
542
+ for (const key in retailActiveEvents) {
543
+ if (Object.hasOwnProperty.call(retailActiveEvents, key)) {
544
+ priceMap[key+'-WRTL'] = retailActiveEvents[key].price;
545
+ offerId = offerId || key;
546
+ }
547
+ }
548
+ for (const key in wholesaleActiveEvents) {
549
+ if (Object.hasOwnProperty.call(wholesaleActiveEvents, key)) {
550
+ priceMap[key+'-WWHL'] = wholesaleActiveEvents[key].price;
551
+ cvMap[key+'-WWHL'] = wholesaleActiveEvents[key].cv;
552
+ pvMap[key+'-WWHL'] = wholesaleActiveEvents[key].pv;
553
+ offerId = offerId || key;
554
+ }
555
+ }
556
+ return { priceMap, cvMap, pvMap, message: product.salesLabel, offerId }
557
+ }
558
+
559
+ }
560
+ return { message: product.salesLabel, offerId: null, priceMap: {}, cvMap: {}, pvMap: {} }
608
561
  }
562
+ return {message: null, offerId: null}
563
+ // if (isKitBundle) {
564
+ // const { pricingJson } = product
565
+ // const parsedPricing = JSON.parse(pricingJson)
566
+ // const promotion = parsedPricing.promotion
567
+ // return (promotion && promotion.length >= 1) ? { message: promotion[0].message, offerId: promotion[0].offerId } : { message: '', offerId: '' }
568
+ // } else {
569
+ // return { message: product.salesLabel || product.salesText, offerId: product.salesLabel || product.salesText }
570
+ // }
609
571
 
610
572
  }
611
573
 
@@ -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
- if (config.active) {
28
- return (config.MySite_graphql_active_list.includes(market)) ?
29
- await getProducts(skus, market, locale, config) :
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;
@@ -1,22 +0,0 @@
1
-
2
-
3
- /**
4
- * Map retail subscription price
5
- * Map retailSales if it has sales/promotions
6
- * @param {obj} product
7
- * @return {number} retail subscpription price
8
- */
9
- function retailSubscriptionPrice(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.retailSubscription;
19
-
20
- }
21
-
22
- module.exports = retailSubscriptionPrice;
@@ -1,20 +0,0 @@
1
-
2
-
3
- /**
4
- * Map wholesale price
5
- * Map wholesaleSales if it has sales/promotions
6
- * @param {*} product
7
- * @return {number} wholesalePrice
8
- */
9
- function wholeSalePrice(product) {
10
- const { price, totalPrice } = product;
11
- const productPrice = price ? price : totalPrice;
12
-
13
- if (productPrice.wholesaleSales) {
14
- return productPrice.wholesaleSales;
15
- }
16
-
17
- return productPrice.wholesale;
18
- }
19
-
20
- module.exports = wholeSalePrice;