@nuskin/ns-product-lib 2.5.0-fix.2 → 2.5.1-cx24-3282m.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ const { getConfiguration } = require('@nuskin/configuration-sdk');
3
+ const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
2
4
  const axios = require("axios");
3
5
  const contentstack = require('./contentstack/contentstack');
4
6
  const Product = require("./product");
5
-
7
+ const CustomerTypes = require('./models/customerTypes');
8
+ const ProductStatus = require("./models/productStatus");
6
9
  /** @type {*} */
7
10
  const ProductData = {
8
11
  /**
@@ -15,35 +18,39 @@ const ProductData = {
15
18
  const localeMarket = `${locale}_${market}`;
16
19
 
17
20
  if (isEquinoxEnabled) {
18
- const marketConfig = await contentstack.isMarketEnabled(market);
21
+ let config = (await getConfiguration({
22
+ configMapNames: ['Equinox_Markets'],
23
+ country: market,
24
+ environment: contentstackEnv(),
25
+ clientId: '735b1eb810304bba966af0891ab54053'
26
+ }));
19
27
 
20
- if (marketConfig !== null) {
21
- return await this.getProductFromEquinox(skus, localeMarket, marketConfig.store_id);
28
+ if (config.Equinox_Markets.country_code === market && config.Equinox_Markets.active) {
29
+ return await this.getProductFromEquinox(skus, localeMarket, config);
22
30
  }
23
31
  }
24
-
25
32
  return await this.getProductFromLegacy(skus, localeMarket);
26
33
  },
27
34
 
28
- getProductFromEquinox: async function (skus, locale, storeID) {
29
- const filter = '{"filters":[{"field":"index_key_skuId","operation":"IN","value":"' + skus.toString() + '"}]}';
35
+ getProductFromEquinox: async function (skus, locale, config) {
36
+ const filter = `{"filters": [{"field": "index_key_skuId","operation": "IN", "value": "${skus.toString()}"}]}`;
30
37
  axios.defaults.withCredentials = true;
31
38
 
32
- const url = await contentstack.getKongUrl() + `/orchestrationservices/storefront/catalogs/search/`;
39
+ const url = `${config.Equinox_Markets.API_Base_URLs}/orchestrationservices/storefront/catalogs/search/`;
33
40
  const href = `${url}?filter=${encodeURI(filter)}`;
34
41
  const response = await axios.request({
35
42
  method: 'get',
36
43
  url: href,
37
44
  params: {
38
45
  locale,
39
- storeId: storeID
46
+ storeId: config.Equinox_Markets.store_id
40
47
  },
41
48
  headers: this.getEquinoxRequestHeaders(),
42
49
  responseType: 'json'
43
50
  });
44
51
 
45
52
  if (response.data.product) {
46
- return this.eqProductMapper(response.data.product);
53
+ return this.eqProductMapper(response.data.product, skus);
47
54
  }
48
55
 
49
56
  return {
@@ -81,7 +88,7 @@ const ProductData = {
81
88
  /**
82
89
  * @param {contentstack.MarketConfig} marketConfig
83
90
  */
84
- getLegacyRequestHeaders: function(marketConfig) {
91
+ getLegacyRequestHeaders: function (marketConfig) {
85
92
  return {
86
93
  'Content-Type': 'application/json',
87
94
  client_id: marketConfig.checkout_client_id,
@@ -91,11 +98,11 @@ const ProductData = {
91
98
 
92
99
  /**
93
100
  * Map product variant
94
- * @todo remove unnecessary fields
101
+ * @todo remove unnecessary fields and do code refactoring
95
102
  * @param {*} eqVariant
96
103
  * @returns Array<Product>
97
104
  */
98
- eqProductVariantMapper : function (eqVariant) {
105
+ eqProductVariantMapper: function (eqVariant) {
99
106
 
100
107
  let imageURL = eqVariant.properties.imageURL;
101
108
  const regex = /\d+.\d+/
@@ -104,9 +111,13 @@ const ProductData = {
104
111
  if (imageURL.includes('contentstack')) {
105
112
  thumbnailImage = imageURL + '?width=40'
106
113
  } else {
107
- thumbnailImage = imageURL.replace(regex,'40.40')
114
+ thumbnailImage = imageURL.replace(regex, '40.40')
108
115
  }
109
116
 
117
+ const { eventName, eventLabels, computedPrice, defaultProductPrice } = this.getEqProductPromotions(eqVariant);
118
+ const productPrice = eventName ? defaultProductPrice : eqVariant.priceFacets["Regular Price"];
119
+ const discountedPrice = eventName ? computedPrice : eqVariant.priceFacets["Regular Price"];
120
+
110
121
  return {
111
122
  "sku": eqVariant.identifier,
112
123
  "globalProductID": eqVariant.identifier,
@@ -135,24 +146,94 @@ const ProductData = {
135
146
  "salesEventText": "",
136
147
  "contentSection": [
137
148
  {
138
- "sectionContent": "<div class=\"contentSections\"><div class=\"contentSection section\"><div>\n<h3>BENEFITS</h3>\n<div>\n<div class=\"sectionContent parsys\"><div class=\"text parbase section\">\n<p>Green tea has been used in China for thousands of years for its health-preserving and revitalizing power. Modern science has identified powerful antioxidants in green tea called polyphenols. One group of polyphenols called catechins is particularly potent and is highly effective at neutralizing free radicals at the cellular level. Catechins support healthy cell function while providing antioxidant protection to critical cell structures such as DNA. Clinical studies show catechins interfere with the production of certain enzymes involved in cell damage. Additionally, catechins have been demonstrated to cause a thermogenic effect that enhances the body s metabolic rate. Tegreen 97<sup>®</sup> from Pharmanex is a proprietary, highly concentrated extract of the catechins found in green tea. Tegreen 97<sup>®</sup> is one of the most potent antioxidant supplements on the market with a 97 percent polyphenol content, 65% catechins. Each Tegreen 97<sup>®</sup> capsule contains the catechin equivalent of approximately seven cups of green tea and is 99.5 percent caffeine free.</p>\r\n\n</div>\n\n</div>\n\n</div>\n</div>\n</div>\n<div class=\"contentSection section\"><div>\n<h3>USAGE</h3>\n<div>\n<div class=\"sectionContent parsys\"><div class=\"text parbase section\">\n<p>As a dietary supplement, take one (1) to four (4) capsules daily; preferably one (1) to two (2) each morning and evening with food. Store in a cool, dry place.</p>\r\n\n</div>\n\n</div>\n\n</div>\n</div>\n</div>\n<div class=\"contentSection section\"><div>\n<h3>INGREDIENTS</h3>\n<div>\n<div class=\"sectionContent parsys\"><div class=\"text parbase section\">\n<table border=\"1\" cellspacing=\"1\" cellpadding=\"0\" width=\"360\"><tbody>\r\n<tr>\r\n<td><b>Nutritional Facts</b></td>\r\n<td><b>Amount</b></td>\r\n<td><b>% Daily Value</b></td>\r\n</tr>\r\n<tr>\r\n<td colspan=\"3\"><b>Serving Size: 1 Capsule<br>\r\nServings Per Container: 120</b></td>\r\n</tr>\r\n<tr>\r\n<td width=\"55%\">Green tea leaf (20:1) Extract (<i>Camellia sinensis</i></td>\r\n<td width=\"20%\">250 mg</td>\r\n<td width=\"25%\">&nbsp;</td>\r\n</tr>\r\n<tr>\r\n<td width=\"55%\" colspan=\"3\">* Daily Value not established</td>\r\n</tr>\r\n<tr>\r\n<td width=\"55%\" colspan=\"3\"><b>Other Ingredients: Gelatin, Silicon Dioxide, Microcrystalline Cellulose, Magnesium Stearate.</b></td>\r\n</tr>\r\n</tbody>\r\n</table>\r\n<p>&nbsp;</p>\r\n\n</div>\n\n</div>\n\n</div>\n</div>\n</div>\n</div>\n"
149
+ "sectionContent": `<div class="contentSections">
150
+ <div class="contentSection section">
151
+ <div>\n<h3>BENEFITS</h3>\n
152
+ <div>\n
153
+ <div class="sectionContent parsys">
154
+ <div class="text parbase section">\n
155
+ <p>
156
+ Green tea has been used in China for thousands of years for its health-preserving and
157
+ revitalizing power. Modern science has identified powerful antioxidants in green tea
158
+ called polyphenols. One group of polyphenols called catechins is particularly potent
159
+ and is highly effective at neutralizing free radicals at the cellular level. Catechins
160
+ support healthy cell function while providing antioxidant protection to critical cell
161
+ structures such as DNA. Clinical studies show catechins interfere with the production
162
+ of certain enzymes involved in cell damage. Additionally, catechins have been demonstrated
163
+ to cause a thermogenic effect that enhances the body s metabolic rate. Tegreen 97<sup>®</sup>
164
+ from Pharmanex is a proprietary, highly concentrated extract of the catechins found
165
+ in green tea. Tegreen 97<sup>®</sup> is one of the most potent antioxidant supplements
166
+ on the market with a 97 percent polyphenol content, 65% catechins. Each Tegreen 97<sup>®</sup>
167
+ capsule contains the catechin equivalent of approximately seven cups of green tea and is
168
+ 99.5 percent caffeine free.
169
+ </p>\r\n\n
170
+ </div>\n\n
171
+ </div>\n\n
172
+ </div>\n
173
+ </div>\n
174
+ </div>\n
175
+ <div class="contentSection section">
176
+ <div>\n<h3>USAGE</h3>\n
177
+ <div>\n
178
+ <div class="sectionContent parsys">
179
+ <div class="text parbase section">\n
180
+ <p>As a dietary supplement, take one (1) to four (4) capsules daily; preferably one (1)
181
+ to two (2) each morning and evening with food. Store in a cool, dry place.</p>\r\n\n
182
+ </div>\n\n
183
+ </div>\n\n
184
+ </div>\n
185
+ </div>\n
186
+ </div>\n
187
+ <div class="contentSection section">
188
+ <div>\n<h3>INGREDIENTS</h3>\n
189
+ <div>\n
190
+ <div class="sectionContent parsys">
191
+ <div class="text parbase section">\n
192
+ <table border="1" cellspacing="1" cellpadding="0" width="360">
193
+ <tbody>\r\n
194
+ <tr>\r\n
195
+ <td><b>Nutritional Facts</b></td>\r\n
196
+ <td><b>Amount</b></td>\r\n<td><b>% Daily Value</b></td>\r\n
197
+ </tr>\r\n
198
+ <tr>\r\n
199
+ <td colspan="3"><b>Serving Size: 1 Capsule<br>\r\nServings Per Container: 120</b></td>\r\n
200
+ </tr>\r\n
201
+ <tr>\r\n
202
+ <td width="55%">Green tea leaf (20:1) Extract (<i>Camellia sinensis</i></td>\r\n
203
+ <td width="20%">250 mg</td>\r\n<td width="25%">&nbsp;</td>\r\n
204
+ </tr>\r\n
205
+ <tr>\r\n<td width="55%" colspan="3">* Daily Value not established</td>\r\n</tr>\r\n
206
+ <tr>\r\n
207
+ <td width="55%" colspan="3">
208
+ <b>Other Ingredients: Gelatin, Silicon Dioxide,
209
+ Microcrystalline Cellulose, Magnesium Stearate.</b>
210
+ </td>\r\n</tr>\r\n
211
+ </tbody>\r\n
212
+ </table>\r\n
213
+ <p>&nbsp;</p>\r\n\n
214
+ </div>\n\n
215
+ </div>\n\n
216
+ </div>\n
217
+ </div>\n
218
+ </div>\n
219
+ </div>\n`
139
220
  }
140
221
  ],
141
222
  "scanQualified": eqVariant.properties.scanQualifiedCount,
142
223
  "availableQuantity": eqVariant.inventoryProperties.atpQty,
143
224
  "maxQuantity": 999,
144
225
  "points": "",
145
- "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
146
- "pv":eqVariant.priceFacets.PV,
226
+ "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
227
+ "pv": eqVariant.priceFacets.PV,
147
228
  "priceType": "WRTL",
148
- "price": eqVariant.priceFacets["Regular Price"],
229
+ "price": discountedPrice,
149
230
  "priceMap": {
150
- "WRTL": eqVariant.priceFacets["Regular Price"],
231
+ "WRTL": productPrice,
151
232
  "WADW-WRTL": eqVariant.priceFacets["Regular Price"],
152
- "WADR": 9999.01,
233
+ "WADR": eqVariant.priceFacets["Regular Price"],
153
234
  "RTL": eqVariant.priceFacets["Regular Price"],
154
235
  "WWHL": eqVariant.priceFacets["Wholesale Price"],
155
- "WADW": 9998.01,
236
+ "WADW": eqVariant.priceFacets["Wholesale Price"],
156
237
  "WHL": eqVariant.priceFacets["Wholesale Price"]
157
238
  },
158
239
  "cvMap": {
@@ -165,19 +246,8 @@ const ProductData = {
165
246
  "WADW": eqVariant.priceFacets.PV,
166
247
  "WHL": eqVariant.priceFacets.PV
167
248
  },
168
- "orderTypes": {
169
- "adr": true,
170
- "order": true,
171
- "zpfc": false,
172
- "zadp": true,
173
- "ars": true,
174
- "kiosk": true,
175
- "mobile": true,
176
- "preferred customer": true,
177
- "retail": true,
178
- "web": true,
179
- "web display": true
180
- },
249
+ "orderTypes": this._setOrderType(eqVariant.properties),
250
+ "custTypes": this.switchCustType(eqVariant.properties.customerTypes),
181
251
  "division": eqVariant.properties.division,
182
252
  "backOrderDate": null,
183
253
  "locallyProduced": false,
@@ -188,29 +258,67 @@ const ProductData = {
188
258
  "shade": "",
189
259
  "status": this.switchStatusFromEquinox(eqVariant.properties.status),
190
260
  "variantType": "Other",
191
- "variantDropdownLabel": eqVariant.properties.variantLabel || "",
261
+ "variantDropdownLabel": eqVariant.properties.variantSelectLabel || "",
192
262
  "variantDropdownPlaceholder": "Select Type",
193
- "variantsLabel": eqVariant.properties.variantLabel || "",
263
+ "variantsLabel": eqVariant.properties.variantSelectLabel || "",
194
264
  "groupOffer": false,
195
265
  "personalOffer": false,
196
- "savedEventName": null,
197
- "salesLabel": "",
198
- "eventName": null,
266
+ "savedEventName": eventName,
267
+ "salesLabel": eventLabels,
268
+ "eventName": eventName,
199
269
  "sizeWeight": '',
200
270
  "nettoWeight": "",
201
271
  "searchScore": 0,
202
- "isExclusive": false,
272
+ "isExclusive": eqVariant.properties.isExclusive || false,
203
273
  "marketAttributes": {
204
274
  "discount": true,
205
275
  "redeem": true,
206
276
  "earn": true
207
277
  },
208
278
  "restrictedMarkets": [],
209
- "addOns": []
279
+ "addOns": [],
280
+ "equinoxProductId": eqVariant.identifier
210
281
  };
211
282
  },
212
283
 
213
- eqProductMapper: function (productDataResponse) {
284
+ /**
285
+ * Get EQ product promotions
286
+ * @param {*} product
287
+ * @returns {obj} promotion
288
+ */
289
+ getEqProductPromotions(product) {
290
+
291
+ if (!Array.isArray(product.promotion)) {
292
+ return {
293
+ eventLabels: "",
294
+ computedPrice: 0,
295
+ defaultProductPrice: product.priceFacets ? product.priceFacets["Regular Price"] : 0,
296
+ eventName: null
297
+ }
298
+ }
299
+
300
+ const defaultProductPrice = product.totalValue ? product.totalValue.originalPrice : 0;
301
+ const computedPrice = product.totalValue && product.totalValue.priceAfterDiscount
302
+ ? product.totalValue.priceAfterDiscount
303
+ : 0;
304
+ let eventName = "";
305
+ const eventLabels = [];
306
+
307
+ product.promotion.map(promotion => {
308
+ eventName = promotion.offerId;
309
+ eventLabels.push(promotion.message);
310
+ return promotion;
311
+ });
312
+
313
+ return {
314
+ eventLabels: eventLabels.join(','),
315
+ defaultProductPrice,
316
+ computedPrice,
317
+ eventName
318
+ }
319
+ },
320
+
321
+ eqProductMapper: function (productDataResponse, skus) {
214
322
  let prod = [];
215
323
  let count = 0;
216
324
  let variants = {};
@@ -223,16 +331,26 @@ const ProductData = {
223
331
  if (imageURL.includes('contentstack')) {
224
332
  thumbnailImage = imageURL + '?width=40'
225
333
  } else {
226
- thumbnailImage = imageURL.replace(regex,'40.40')
334
+ thumbnailImage = imageURL.replace(regex, '40.40')
227
335
  }
228
336
 
229
337
  if (data.sku && data.sku.length > 1) {
230
- data.sku.map(variant => {
338
+ //exclude base product from variants
339
+ data.sku.filter(v => v.identifier.substring(2, 4) !== "55").map(variant => {
231
340
  variants[variant.identifier] = this.eqProductVariantMapper(variant);
232
341
  return variant;
233
342
  });
234
343
  }
235
344
 
345
+ const {
346
+ eventName,
347
+ eventLabels,
348
+ computedPrice,
349
+ defaultProductPrice
350
+ } = this.getEqProductPromotions(data.sku[count]);
351
+ const productPrice = eventName ? defaultProductPrice : data.sku[count].priceFacets["Regular Price"];
352
+ const discountedPrice = eventName ? computedPrice : data.sku[count].priceFacets["Regular Price"];
353
+
236
354
  prod = {
237
355
  "sku": data.sku[count].identifier,
238
356
  "globalProductID": data.identifier,
@@ -268,16 +386,16 @@ const ProductData = {
268
386
  "availableQuantity": data.sku[count].inventoryProperties.atpQty,
269
387
  "maxQuantity": 999,
270
388
  "points": "",
271
- "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
389
+ "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
272
390
  "pv": data.sku[count].priceFacets.PV,
273
391
  "priceType": "WRTL",
274
- "price": data.sku[count].priceFacets["Regular Price"],
392
+ "price": discountedPrice,
275
393
  "priceMap": {
276
- "WRTL": data.sku[count].priceFacets["Regular Price"],
394
+ "WRTL": productPrice,
277
395
  "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
278
- "WADR": 9999.01,
396
+ "WADR": data.sku[count].priceFacets["Regular Price"],
279
397
  "RTL": data.sku[count].priceFacets["Regular Price"],
280
- "WADW": 9998.01,
398
+ "WADW": data.sku[count].priceFacets["Wholesale Price"],
281
399
  "WHL": data.sku[count].priceFacets["Wholesale Price"],
282
400
  "WWHL": data.sku[count].priceFacets["Wholesale Price"]
283
401
  },
@@ -291,21 +409,9 @@ const ProductData = {
291
409
  "WADW": data.sku[count].priceFacets.PV,
292
410
  "WHL": data.sku[count].priceFacets.PV
293
411
  },
294
- "orderTypes": {
295
- "adr": true,
296
- "order": true,
297
- "zpfc": false,
298
- "zadp": true,
299
- "ars": true,
300
- "kiosk": true,
301
- "mobile": true,
302
- "preferred customer": true,
303
- "retail": true,
304
- "web": true,
305
- "web display": true
306
- },
412
+ "orderTypes": this._setOrderType(data.sku[count].properties),
307
413
  "childSkus": [],
308
- "custTypes": this.switchCustType(data.properties.customerTypes),
414
+ "custTypes": this.switchCustType(data.sku[count].properties.customerTypes),
309
415
  "division": data.properties.division,
310
416
  "backOrderDate": null,
311
417
  "locallyProduced": false,
@@ -316,19 +422,19 @@ const ProductData = {
316
422
  "shade": "",
317
423
  "status": this.switchStatusFromEquinox(data.sku[count].properties.productStatus),
318
424
  "variantType": "Other",
319
- "variantDropdownLabel": data.sku[count].properties.variantLabel || "",
425
+ "variantDropdownLabel": data.sku[count].properties.variantLabel || "",
320
426
  "variantDropdownPlaceholder": "Select Type",
321
- "variantsLabel": data.sku[count].properties.variantLabel || "",
427
+ "variantsLabel": data.sku[count].properties.variantLabel || "",
322
428
  "groupOffer": false,
323
429
  "personalOffer": false,
324
- "savedEventName": null,
325
- "salesLabel": "",
326
- "eventName": null,
430
+ "savedEventName": eventName,
431
+ "salesLabel": eventLabels,
432
+ "eventName": eventName,
327
433
  "sizeWeight": '',
328
434
  "nettoWeight": "",
329
435
  "variants": variants,
330
436
  "searchScore": 0,
331
- "isExclusive": data.sku[count].properties.isExclusive,
437
+ "isExclusive": data.sku[count].properties.isExclusive || false,
332
438
  "marketAttributes": {
333
439
  "discount": true,
334
440
  "redeem": true,
@@ -336,15 +442,15 @@ const ProductData = {
336
442
  },
337
443
  "restrictedMarkets": [],
338
444
  "addOns": [],
339
- "inventory": data.sku[count].inventory || "" //inventory label
340
-
445
+ "inventory": data.sku[count].inventory || "", //inventory label
446
+ "equinoxProductId": data.identifier
341
447
  };
342
448
  let newProduct = new Product(prod);
343
449
  return newProduct
344
- })
450
+ });
345
451
 
346
452
  let data = {
347
- products: prodArr,
453
+ products: this._sortProductsBySku(skus, prodArr),
348
454
  count: productDataResponse.length
349
455
  };
350
456
  return {
@@ -356,46 +462,152 @@ const ProductData = {
356
462
  };
357
463
  },
358
464
 
465
+ /**
466
+ *
467
+ * Map status from equinox to legacy
468
+ *
469
+ * @param {*} status
470
+ * @returns {string} productStatus
471
+ */
359
472
  switchStatusFromEquinox: function (status) {
473
+ const { equinoxStatus } = ProductStatus;
360
474
  let newStatus = '';
361
- switch (status) {
362
- case 'Sellable':
363
- newStatus = 'RELEASED_FOR_SALE';
475
+ switch (status.toLowerCase()) {
476
+ case equinoxStatus.SELLABLE:
477
+ newStatus = ProductStatus.ReleasedForSale;
364
478
  break;
365
- case 'Preview product':
366
- newStatus = 'NOT_RELEASED_FOR_SALE';
479
+ case equinoxStatus.PREVIEW_PRODUCT:
480
+ newStatus = ProductStatus.NotReleasedForSale;
367
481
  break;
368
- case 'Discontinued':
369
- newStatus = 'DISCONTINUED';
482
+ case equinoxStatus.DISCONTINUED:
483
+ newStatus = ProductStatus.Discontinued;
370
484
  break;
371
- case 'Stopped':
372
- newStatus = 'DISCONTINUED';
485
+ case equinoxStatus.STOPPED:
486
+ newStatus = ProductStatus.Discontinued;
373
487
  break;
374
- case 'Replacement':
375
- newStatus = 'NOT_RELEASED_FOR_SALE';
488
+ case equinoxStatus.REPLACEMENT:
489
+ newStatus = ProductStatus.NotReleasedForSale;
376
490
  break;
377
491
  default:
378
- newStatus = 'NOT_RELEASED_FOR_SALE'
492
+ newStatus = ProductStatus.NotReleasedForSale;
379
493
  break;
380
494
  }
495
+
381
496
  return newStatus;
382
497
  },
383
498
 
384
499
  /**
385
- *
386
- * @param {*} custType
387
- *
500
+ * map customer types from string to code<number>
501
+ * @param {*} eqCustomerTypes
502
+ * @returns
388
503
  */
389
- switchCustType: function (custType) {
504
+ switchCustType: function (eqCustomerTypes) {
505
+ if (!eqCustomerTypes) {
506
+ return "";
507
+ }
508
+
509
+ const custTypes = eqCustomerTypes.split(',').map(customerType => customerType.trim().toLowerCase());
510
+
390
511
  let newCustType = [];
391
- if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
392
- newCustType.push(10)
393
- if (custType.includes('Retail Customer'))
394
- newCustType.push(20)
395
- if (custType.includes('Preferred Customer/Member'))
396
- newCustType.push(30)
512
+ if (custTypes.includes(CustomerTypes.BrandAffiliate)) {
513
+ newCustType.push(CustomerTypes.properties.BRAND_AFFILIATE.code);
514
+ }
515
+
516
+ if (custTypes.includes(CustomerTypes.Retail)) {
517
+ newCustType.push(CustomerTypes.properties.RETAIL.code);
518
+ }
519
+
520
+ if (custTypes.includes(CustomerTypes.Preferred) || custTypes.includes(CustomerTypes.PreferredCustomer)) {
521
+ newCustType.push(CustomerTypes.properties.PREFERRED.code);
522
+ }
523
+
397
524
  return newCustType.toString()
525
+ },
526
+
527
+ /**
528
+ * Sorts the product by sku
529
+ * @param {Array} skus - the skus arrangment which the sorting will base out of
530
+ * @param {Array} products - this products to be sorted
531
+ */
532
+
533
+ _sortProductsBySku: function (skus, products) {
534
+
535
+ if (!skus || !products || products.length === 1) {
536
+ return products
537
+ }
538
+
539
+ const sortedProducts = products.sort(function (a, b) {
540
+ return skus.indexOf(a.sku) - skus.indexOf(b.sku);
541
+ });
542
+
543
+ return sortedProducts
544
+
545
+ },
546
+
547
+ /**
548
+ *
549
+ * @param {*} availableChannels
550
+ *
551
+ * This function is use to convert arsPhone,web,kiosk,mobile,subscription
552
+ * to orderType object
553
+ * "adr”
554
+ "order"
555
+ "zpfc"
556
+ "zadp"
557
+ "ars"
558
+ "kiosk"
559
+ "mobile"
560
+ "preferred customer"
561
+ "retail"
562
+ "web"
563
+ "web display"
564
+ */
565
+ _setOrderType: function (properties) {
566
+ let orderTypeArr = {
567
+ "adr": false,
568
+ "order": false,
569
+ "zpfc": false,
570
+ "zadp": false,
571
+ "ars": false,
572
+ "kiosk": false,
573
+ "mobile": false,
574
+ "preferred customer": false,
575
+ "retail": false,
576
+ "web": false,
577
+ "web display": false
578
+ };
579
+ let availableChannelsArr = properties.availableChannels.split(',')
580
+
581
+ availableChannelsArr.forEach(channel => {
582
+ if (channel == 'arsPhone')
583
+ orderTypeArr.ars = true
584
+ if (channel == 'web') {
585
+ orderTypeArr.order = true
586
+ orderTypeArr.web = true
587
+ }
588
+ if (channel == 'kiosk')
589
+ orderTypeArr.kiosk = true
590
+ if (channel == 'mobile')
591
+ orderTypeArr.mobile = true
592
+ if (channel == 'subscription')
593
+ orderTypeArr.adr = true
594
+
595
+ });
596
+ if (properties.retail)
597
+ orderTypeArr.retail = true
598
+ if (properties.prefferredCustomer)
599
+ orderTypeArr['preferred customer'] = true
600
+
601
+ return orderTypeArr;
398
602
  }
399
603
  }
400
604
 
605
+ function contentstackEnv() {
606
+ if (typeof window === 'undefined') {
607
+ return 'test';
608
+ }
609
+
610
+ return (getEnvironmentFromUrl(window.location.host) != "prod") ? "test" : "prod";
611
+ }
612
+
401
613
  module.exports = ProductData;
File without changes