@nuskin/ns-product-lib 2.5.0-cx24-3175.1 → 2.5.0-cx24-2179.2.12

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,123 @@
1
- # [2.5.0-cx24-3175.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.1...v2.5.0-cx24-3175.1) (2023-01-20)
1
+ # [2.5.0-cx24-2179.2.12](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.11...v2.5.0-cx24-2179.2.12) (2023-01-23)
2
+
3
+
4
+ ### Fix
5
+
6
+ * undefined value of the URL (CX24-3122,CX24-3234) ([f4c1837](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/f4c1837d44da364711cc65b0c7c7a0c02f225f2e))
7
+
8
+ # [2.5.0-cx24-2179.2.11](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.10...v2.5.0-cx24-2179.2.11) (2023-01-16)
9
+
10
+
11
+ ### Fix
12
+
13
+ * Equinox API called for non equinox market ([50eaa48](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/50eaa48a41a9e00d48ff79de35b955b817c4c0ea))
14
+
15
+ # [2.5.0-cx24-2179.2.10](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.9...v2.5.0-cx24-2179.2.10) (2023-01-16)
16
+
17
+
18
+ ### Fix
19
+
20
+ * Equinox API called for non equinox market (CX24-3168) ([399e615](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/399e6150914dcafd5bd9fcd7ca0e0a95b65656d7))
21
+
22
+ # [2.5.0-cx24-2179.2.9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.8...v2.5.0-cx24-2179.2.9) (2022-12-20)
23
+
24
+
25
+ ### Fix
26
+
27
+ * eq market event pricing and name (#CX24-2179) ([213b59a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/213b59a33a208ffad0a6726521ce7f365d34d36e)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
28
+ * Slow response of add-to-cart button function for Equinox Cart ([14394b2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/14394b299afbd53254a3ec053ad41e68ed526dfe))
29
+ * Unit Tests ([ace52c6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ace52c6418991d0263a1e1f8d99901e724abf923))
30
+
31
+ ### Release
32
+
33
+ * Automated changes by GitLab pipeline [skip ci] ([eb755fa](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/eb755fae1e1f1f221a34d92f5ff4e64787a4132d))
34
+ * Automated changes by GitLab pipeline [skip ci] ([6a75f7a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/6a75f7a5f8b2f3b17e4d7387af37cad4f367b45c))
35
+
36
+ ### Update
37
+
38
+ * use configuration-sdk to pull the configurations (CX24-2931) ([6934570](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/69345701e6b44754ffeb648ead56f0288aadeb16))
39
+
40
+ # [2.5.0-CX24.3.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.2-CX24.2.1...v2.5.0-CX24.3.1) (2022-12-06)
41
+
42
+ * added eq promoion bypass for setPriceAndPvFromType v5 (#CX24-2179) ([f5b62e5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/f5b62e5e82f1830d4105ffc965b64e9a7fc88d9b)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
43
+
44
+ # [2.5.0-cx24-2179.2.6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.5...v2.5.0-cx24-2179.2.6) (2022-12-05)
45
+
46
+
47
+ ### New
48
+
49
+ * added eq promoion bypass for setPriceAndPvFromType v4 (#CX24-2179) ([abcdd30](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/abcdd30223107786c0c2f9d1a8946053ef6dcef5)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
50
+
51
+ # [2.5.0-cx24-2179.2.5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.4...v2.5.0-cx24-2179.2.5) (2022-12-05)
52
+
53
+
54
+ ### New
55
+
56
+ * added eq promoion bypass for setPriceAndPvFromType v3 (#CX24-2179) ([79fe156](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/79fe1562d0cafc44f8945e57c316c8ba0b55a88b)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
57
+
58
+ # [2.5.0-cx24-2179.2.4](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.3...v2.5.0-cx24-2179.2.4) (2022-12-05)
59
+
60
+
61
+ ### New
62
+
63
+ * added eq promoion bypass for setPriceAndPvFromType v2 (#CX24-2179) ([25bde9a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/25bde9a8e19b1e4e44e37457dfb087e0a6212ee1)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
64
+
65
+ # [2.5.0-cx24-2179.2.3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.2...v2.5.0-cx24-2179.2.3) (2022-12-05)
66
+
67
+
68
+ ### New
69
+
70
+ * added eq promoion bypass for setPriceAndPvFromType (#CX24-2179) ([716cefc](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/716cefc2a2522287e017709a8b2cfef5a7ce5e07)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
71
+
72
+ # [2.5.0-cx24-2179.2.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.1...v2.5.0-cx24-2179.2.2) (2022-12-05)
73
+
74
+
75
+ ### New
76
+
77
+ * added eq promotion support- debug sales event (#CX24-2179) ([992a2cf](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/992a2cfb178b3e12a6b8a0229ae5f6f607fb41d3)), closes [#CX24-2179](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2179)
78
+
79
+ # [2.5.0-cx24-2179.2.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.2-CX24.2.1...v2.5.0-cx24-2179.2.1) (2022-12-02)
80
+ >>>>>>> CX24.2
81
+
82
+
83
+ ### Fix
84
+
85
+ * [Equinox market] Admin > Move up/down/top/bottom of featured products and edit bundle is not working ([a89af4a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/a89af4a5d00c6a68fcaeff22f128554270add21e))
86
+
87
+ ### Release
88
+
89
+ * Automated changes by GitLab pipeline [skip ci] ([07bfa40](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/07bfa404c552c05637c2c8a537c4ff298536874e))
90
+ * Automated changes by GitLab pipeline [skip ci] ([fa1c0d9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/fa1c0d9d5853482e3ac49cea4e99599e7192f85b))
91
+ * Automated changes by GitLab pipeline [skip ci] ([2d20787](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/2d2078763b2d57edb8a24f438ac90dd37c3ff41b))
92
+
93
+ ### Update
94
+
95
+ * set ADR pricing from equinox (CX24-2862) ([65d04d2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/65d04d2e9ff4018edfe99e5a7412bee985d3def2))
96
+ * set ADR pricing from equinox (CX24-2862) ([54a5693](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/54a56932e5df36c9c30ce6358d8597c98be3d20d))
97
+ * set ADR pricing from equinox (CX24-2862) ([bbd135f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bbd135f1ed0395c578be2274c84ba136ceed9376))
98
+ * set ADR pricing from equinox (CX24-2862) ([197003e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/197003e1629bd394c547a118d332b5e8574dfc7d))
99
+
100
+ # [2.5.0-cx24-2862.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2862.1...v2.5.0-cx24-2862.2) (2022-11-11)
101
+
102
+
103
+ ### Update
104
+
105
+ * set ADR pricing from equinox (CX24-2862) ([b64dcea](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b64dcea4dd3374be992c667db5c0b2604aacc029))
106
+
107
+ # [2.5.0-cx24-2862.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.2-cx24-2612.1.1...v2.5.0-cx24-2862.1) (2022-11-10)
2
108
 
3
109
 
4
110
  ### Update
5
111
 
6
- * remapped equinox isExclusive field (#CX24-3175) ([6adcee1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/6adcee103ca720697152d253c135546af7393739)), closes [#CX24-3175](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3175)
7
- * remapped equinox properties after migration (#CX24-3175) ([cd1e3f6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/cd1e3f6894b764283b026197412a6d1859b35a91)), closes [#CX24-3175](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3175)
8
- * remapped equinox variant label property (#CX24-3175) ([3c2a7dc](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3c2a7dc4c9543577ae6a90f3f5df0f092707e2b6)), closes [#CX24-3175](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-3175)
112
+ * set ADR pricing from equinox (CX24-2862) ([9f6dfb7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9f6dfb726f40b1335411318629a2ebdf1b4dac96))
113
+ * set ADR pricing from equinox (CX24-2862) ([61f550a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/61f550a21c5cc9d062549ec2aaf2758aebccf2be))
114
+
115
+ ## [2.4.2-cx24-2612.1.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.1...v2.4.2-cx24-2612.1.1) (2022-11-07)
116
+
117
+
118
+ ### Fix
119
+
120
+ * [Equinox market] Admin > Move up/down/top/bottom of featured products and edit bundle is not working ([9d9d106](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9d9d10667477b4c7ef7bf8ec013aab322d3cdbcc))
9
121
 
10
122
  ## [2.4.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.0...v2.4.1) (2022-11-06)
11
123
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.5.0-cx24-3175.1",
3
+ "version": "2.5.0-cx24-2179.2.12",
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": {
@@ -31,6 +31,7 @@
31
31
  "prettier": "1.19.1"
32
32
  },
33
33
  "dependencies": {
34
+ "@nuskin/configuration-sdk": "1.0.1",
34
35
  "@nuskin/ns-common-lib": "1.4.5",
35
36
  "@nuskin/ns-util": "3.107.0",
36
37
  "axios": "0.27.2",
@@ -98,7 +98,7 @@ function getCachedData(key) {
98
98
  * @property {string} checkout_client_secret
99
99
  *
100
100
  * @export
101
- * @return {Promise<null|MarketConfig>}
101
+ * @return {Promise<null|MarketConfig>}
102
102
  */
103
103
  async function getAEMConfig() {
104
104
  try {
@@ -137,7 +137,7 @@ async function getAEMConfig() {
137
137
  * @property {string} market_name
138
138
  * @property {string} country_code
139
139
  * @property {string} store_id
140
- *
140
+ *
141
141
  * @typedef EquinoxEnabledMarkets
142
142
  * @property {EquinoxEnabledMarket[]} [dev_markets]
143
143
  * @property {EquinoxEnabledMarket[]} [test_markets]
@@ -145,7 +145,7 @@ async function getAEMConfig() {
145
145
  * @property {EquinoxEnabledMarket[]} [prod_markets]
146
146
  *
147
147
  * @export
148
- * @return {Promise<EquinoxEnabledMarkets>}
148
+ * @return {Promise<EquinoxEnabledMarkets>}
149
149
  */
150
150
  async function getEquinoxMarkets() {
151
151
  try {
@@ -176,8 +176,8 @@ async function getEquinoxMarkets() {
176
176
  }
177
177
  }
178
178
 
179
- /**getKongUrl gets the URL for Kong in contentstack
180
- *
179
+ /**getKongUrl gets the URL for Kong in contentstack
180
+ *
181
181
  * @returns {string}
182
182
  */
183
183
  async function getKongUrl() {
package/src/index.js CHANGED
@@ -7,10 +7,10 @@
7
7
 
8
8
  const Agelocme = require("./agelocme.js");
9
9
  const Contentstack = require('./contentstack/contentstack');
10
- const PriceType = require("./models/priceType.js");
10
+ const PriceType = require("./priceType.js");
11
11
  const Product = require("./product.js");
12
12
  const ProductContentMapper = require("./productContentMapper.js");
13
- const ProductStatus = require("./models/productStatus.js");
13
+ const ProductStatus = require("./productStatus.js");
14
14
  const ProductStatusMapper = require("./productStatusMapper.js");
15
15
  const ProductUtils = require("./productUtils.js");
16
16
  const ProductData = require("./productData.js");
File without changes
package/src/product.js CHANGED
@@ -5,8 +5,8 @@ const { isTrue } = require("@nuskin/ns-common-lib");
5
5
  const ProductUtils = require("./productUtils.js");
6
6
 
7
7
  const Agelocme = require("./agelocme.js");
8
- const PriceType = require("./models/priceType.js");
9
- const ProductStatus = require("./models/productStatus.js");
8
+ const PriceType = require("./priceType.js");
9
+ const ProductStatus = require("./productStatus.js");
10
10
 
11
11
  const Product = function(productData) {
12
12
  this.priceMap = {};
@@ -75,6 +75,7 @@ const Product = function(productData) {
75
75
  //equinox inventory / stock label
76
76
  //@example "IN STOCK"
77
77
  this.inventory = "";
78
+ this.equinoxProductId = "";
78
79
 
79
80
  this.setMarketAttributes = function(productStatus) {
80
81
  if (productStatus.marketAttributes) {
@@ -225,7 +226,7 @@ const Product = function(productData) {
225
226
  }
226
227
  };
227
228
 
228
- this.setPriceAndPvFromType = function(_priceType, _activeEvents = null) {
229
+ this.setPriceAndPvFromType = function(_priceType, _activeEvents = null, option = {}) {
229
230
  // WARNING: priceType needs to be handled client-side
230
231
  // const priceType = ConfigService.getMarketConfig().showWholeSalePricing && !AccountManager.isLoggedIn()
231
232
  // ? PriceType.WWHL
@@ -234,11 +235,11 @@ const Product = function(productData) {
234
235
  const eventPricing = getEventPricing(this, priceType, _activeEvents);
235
236
 
236
237
  let changed = false;
237
- if (
238
+ if ((
238
239
  !this.price ||
239
240
  priceType !== this.priceType ||
240
241
  this.eventName !== eventPricing.eventName
241
- ) {
242
+ ) && !option.isEqPromotion) {
242
243
  this.setPrice(eventPricing.price || this.getPricing(priceType));
243
244
  this.setCv(eventPricing.cv || this.getCvWithType(priceType));
244
245
  this.setPv(eventPricing.pv || this.getPvWithType(priceType));
@@ -247,11 +248,20 @@ const Product = function(productData) {
247
248
  changed = true;
248
249
  }
249
250
 
251
+ if (option.isEqPromotion) {
252
+ //retain product.price as original price
253
+ this.setCv(this.getCvWithType(priceType));
254
+ this.setPv(this.getPvWithType(priceType));
255
+ this.priceType = priceType;
256
+ changed = true;
257
+ }
258
+
250
259
  this.variantSkus().forEach((variantSku) => {
251
260
  if (
252
261
  this.variants[variantSku].setPriceAndPvFromType(
253
262
  priceType,
254
- _activeEvents
263
+ _activeEvents,
264
+ option
255
265
  )
256
266
  ) {
257
267
  changed = true;
@@ -281,7 +291,7 @@ const Product = function(productData) {
281
291
  this.priceMap[type] = price;
282
292
  };
283
293
 
284
- this.addPricingFromStatus = function(productStatus, priceType) {
294
+ this.addPricingFromStatus = function(productStatus, priceType, option ={}) {
285
295
  let modified = false;
286
296
 
287
297
  if (!priceType) {
@@ -319,13 +329,13 @@ const Product = function(productData) {
319
329
  if(productStatus.childSkus) {
320
330
  this.childSkus = productStatus.childSkus;
321
331
  }
322
- this.setPriceAndPvFromType(priceType);
332
+ this.setPriceAndPvFromType(priceType, null, option);
323
333
  modified = true;
324
334
  } else {
325
335
  let variant = this.getVariant(productStatusSku);
326
336
 
327
337
  if (variant) {
328
- if (variant.addPricingFromStatus(productStatus, priceType)) {
338
+ if (variant.addPricingFromStatus(productStatus, priceType, option)) {
329
339
  variant.setMarketAttributes(productStatus);
330
340
  updateBaseRanges(this, variant);
331
341
  modified = true;
@@ -523,6 +533,7 @@ const Product = function(productData) {
523
533
  retData.restrictedMarkets = this.restrictedMarkets;
524
534
  retData.addOns = this.addOns;
525
535
  retData.inventory = this.inventory;
536
+ retData.equinoxProductId = this.equinoxProductId;
526
537
 
527
538
  return retData;
528
539
  };
@@ -662,6 +673,8 @@ const Product = function(productData) {
662
673
  if (data.agelocme) {
663
674
  this.agelocme = new Agelocme(data.agelocme);
664
675
  }
676
+
677
+ this.equinoxProductId = data.equinoxProductId;
665
678
  }
666
679
  };
667
680
 
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
+ const { getConfiguration } = require('@nuskin/configuration-sdk');
3
+ // import { ConfigService } from '@nuskin/ns-util';
2
4
  const axios = require("axios");
3
5
  const contentstack = require('./contentstack/contentstack');
4
6
  const Product = require("./product");
5
- const CustomerTypes = require('./models/customerTypes');
6
- const ProductStatus = require("./models/productStatus");
7
+
7
8
  /** @type {*} */
8
9
  const ProductData = {
9
10
  /**
@@ -14,37 +15,41 @@ const ProductData = {
14
15
  */
15
16
  getProductData: async function (skus, locale, market, isEquinoxEnabled = false) {
16
17
  const localeMarket = `${locale}_${market}`;
17
-
18
+
18
19
  if (isEquinoxEnabled) {
19
- const marketConfig = await contentstack.isMarketEnabled(market);
20
-
21
- if (marketConfig !== null) {
22
- return await this.getProductFromEquinox(skus, localeMarket, marketConfig.store_id);
20
+ let config = (await getConfiguration({
21
+ configMapNames: ['Equinox_Markets'],
22
+ country: market,
23
+ environment: 'test',
24
+ clientId: '735b1eb810304bba966af0891ab54053'
25
+ })).Equinox_Markets;
26
+ if (config.country_code != '') {
27
+ return await this.getProductFromEquinox(skus, localeMarket, config);
23
28
  }
24
29
  }
25
-
26
30
  return await this.getProductFromLegacy(skus, localeMarket);
27
31
  },
28
-
29
- getProductFromEquinox: async function (skus, locale, storeID) {
30
- const filter = '{"filters":[{"field":"index_key_skuId","operation":"IN","value":"' + skus.toString() + '"}]}';
32
+
33
+ getProductFromEquinox: async function (skus, locale, config) {
34
+
35
+ const filter = `{"filters": [{"field": "index_key_skuId","operation": "IN", "value": "${skus.toString()}"}]}`;
31
36
  axios.defaults.withCredentials = true;
32
37
 
33
- const url = await contentstack.getKongUrl() + `/orchestrationservices/storefront/catalogs/search/`;
38
+ const url = `${config.Equinox_Markets.API_Base_URLs}/orchestrationservices/storefront/catalogs/search/`;
34
39
  const href = `${url}?filter=${encodeURI(filter)}`;
35
40
  const response = await axios.request({
36
41
  method: 'get',
37
42
  url: href,
38
43
  params: {
39
44
  locale,
40
- storeId: storeID
45
+ storeId: config.Equinox_Markets.store_id
41
46
  },
42
47
  headers: this.getEquinoxRequestHeaders(),
43
48
  responseType: 'json'
44
49
  });
45
50
 
46
51
  if (response.data.product) {
47
- return this.eqProductMapper(response.data.product);
52
+ return this.eqProductMapper(response.data.product, skus);
48
53
  }
49
54
 
50
55
  return {
@@ -92,11 +97,11 @@ const ProductData = {
92
97
 
93
98
  /**
94
99
  * Map product variant
95
- * @todo remove unnecessary fields
100
+ * @todo remove unnecessary fields and do code refactoring
96
101
  * @param {*} eqVariant
97
102
  * @returns Array<Product>
98
103
  */
99
- j : function (eqVariant) {
104
+ eqProductVariantMapper : function (eqVariant) {
100
105
 
101
106
  let imageURL = eqVariant.properties.imageURL;
102
107
  const regex = /\d+.\d+/
@@ -108,6 +113,10 @@ const ProductData = {
108
113
  thumbnailImage = imageURL.replace(regex,'40.40')
109
114
  }
110
115
 
116
+ const { eventName, eventLabels, computedPrice, defaultProductPrice} = this.getEqProductPromotions(eqVariant);
117
+ const productPrice = eventName ? defaultProductPrice : eqVariant.priceFacets["Regular Price"];
118
+ const discountedPrice = eventName ? computedPrice : eqVariant.priceFacets["Regular Price"];
119
+
111
120
  return {
112
121
  "sku": eqVariant.identifier,
113
122
  "globalProductID": eqVariant.identifier,
@@ -146,14 +155,14 @@ const ProductData = {
146
155
  "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
147
156
  "pv":eqVariant.priceFacets.PV,
148
157
  "priceType": "WRTL",
149
- "price": eqVariant.priceFacets["Regular Price"],
158
+ "price": discountedPrice,
150
159
  "priceMap": {
151
- "WRTL": eqVariant.priceFacets["Regular Price"],
160
+ "WRTL": productPrice,
152
161
  "WADW-WRTL": eqVariant.priceFacets["Regular Price"],
153
- "WADR": 9999.01,
162
+ "WADR": eqVariant.priceFacets["Regular Price"],
154
163
  "RTL": eqVariant.priceFacets["Regular Price"],
155
164
  "WWHL": eqVariant.priceFacets["Wholesale Price"],
156
- "WADW": 9998.01,
165
+ "WADW": eqVariant.priceFacets["Wholesale Price"],
157
166
  "WHL": eqVariant.priceFacets["Wholesale Price"]
158
167
  },
159
168
  "cvMap": {
@@ -166,19 +175,7 @@ const ProductData = {
166
175
  "WADW": eqVariant.priceFacets.PV,
167
176
  "WHL": eqVariant.priceFacets.PV
168
177
  },
169
- "orderTypes": {
170
- "adr": true,
171
- "order": true,
172
- "zpfc": false,
173
- "zadp": true,
174
- "ars": true,
175
- "kiosk": true,
176
- "mobile": true,
177
- "preferred customer": true,
178
- "retail": true,
179
- "web": true,
180
- "web display": true
181
- },
178
+ "orderTypes": this._setOrderType(eqVariant.properties),
182
179
  "division": eqVariant.properties.division,
183
180
  "backOrderDate": null,
184
181
  "locallyProduced": false,
@@ -189,29 +186,65 @@ const ProductData = {
189
186
  "shade": "",
190
187
  "status": this.switchStatusFromEquinox(eqVariant.properties.status),
191
188
  "variantType": "Other",
192
- "variantDropdownLabel": eqVariant.properties.variantSelectLabel || "",
189
+ "variantDropdownLabel": eqVariant.properties.variantLabel || "",
193
190
  "variantDropdownPlaceholder": "Select Type",
194
- "variantsLabel": eqVariant.properties.variantSelectLabel || "",
191
+ "variantsLabel": eqVariant.properties.variantLabel || "",
195
192
  "groupOffer": false,
196
193
  "personalOffer": false,
197
- "savedEventName": null,
198
- "salesLabel": "",
199
- "eventName": null,
194
+ "savedEventName": eventName,
195
+ "salesLabel": eventLabels,
196
+ "eventName": eventName,
200
197
  "sizeWeight": '',
201
198
  "nettoWeight": "",
202
199
  "searchScore": 0,
203
- "isExclusive": eqVariant.properties.isExclusive || false,
200
+ "isExclusive": false,
204
201
  "marketAttributes": {
205
202
  "discount": true,
206
203
  "redeem": true,
207
204
  "earn": true
208
205
  },
209
206
  "restrictedMarkets": [],
210
- "addOns": []
207
+ "addOns": [],
208
+ "equinoxProductId": eqVariant.identifier
211
209
  };
212
210
  },
213
211
 
214
- eqProductMapper: function (productDataResponse) {
212
+ /**
213
+ * Get EQ product promotions
214
+ * @param {*} product
215
+ * @returns {obj} promotion
216
+ */
217
+ getEqProductPromotions(product) {
218
+
219
+ if (!Array.isArray(product.promotion)) {
220
+ return {
221
+ eventLabels: "",
222
+ computedPrice : 0,
223
+ defaultProductPrice: product.priceFacets ? product.priceFacets["Regular Price"] : 0,
224
+ eventName: null
225
+ }
226
+ }
227
+
228
+ const defaultProductPrice = product.totalValue ? product.totalValue.originalPrice : 0;
229
+ const computedPrice = product.totalValue && product.totalValue.priceAfterDiscount ? product.totalValue.priceAfterDiscount : 0;
230
+ let eventName = "";
231
+ const eventLabels = [];
232
+
233
+ product.promotion.map(promotion => {
234
+ eventName = promotion.offerId;
235
+ eventLabels.push(promotion.message);
236
+ return promotion;
237
+ });
238
+
239
+ return {
240
+ eventLabels: eventLabels.join(','),
241
+ defaultProductPrice,
242
+ computedPrice,
243
+ eventName
244
+ }
245
+ },
246
+
247
+ eqProductMapper: function (productDataResponse, skus) {
215
248
  let prod = [];
216
249
  let count = 0;
217
250
  let variants = {};
@@ -228,12 +261,17 @@ const ProductData = {
228
261
  }
229
262
 
230
263
  if (data.sku && data.sku.length > 1) {
231
- data.sku.map(variant => {
264
+ //exclude base product from variants
265
+ data.sku.filter(v => v.identifier.substring(2, 4) !== "55").map(variant => {
232
266
  variants[variant.identifier] = this.eqProductVariantMapper(variant);
233
267
  return variant;
234
268
  });
235
269
  }
236
270
 
271
+ const { eventName, eventLabels, computedPrice, defaultProductPrice} = this.getEqProductPromotions(data.sku[count]);
272
+ const productPrice = eventName ? defaultProductPrice : data.sku[count].priceFacets["Regular Price"];
273
+ const discountedPrice = eventName ? computedPrice : data.sku[count].priceFacets["Regular Price"];
274
+
237
275
  prod = {
238
276
  "sku": data.sku[count].identifier,
239
277
  "globalProductID": data.identifier,
@@ -272,13 +310,13 @@ const ProductData = {
272
310
  "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
273
311
  "pv": data.sku[count].priceFacets.PV,
274
312
  "priceType": "WRTL",
275
- "price": data.sku[count].priceFacets["Regular Price"],
313
+ "price": discountedPrice,
276
314
  "priceMap": {
277
- "WRTL": data.sku[count].priceFacets["Regular Price"],
315
+ "WRTL": productPrice,
278
316
  "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
279
- "WADR": 9999.01,
317
+ "WADR": data.sku[count].priceFacets["Regular Price"],
280
318
  "RTL": data.sku[count].priceFacets["Regular Price"],
281
- "WADW": 9998.01,
319
+ "WADW": data.sku[count].priceFacets["Wholesale Price"],
282
320
  "WHL": data.sku[count].priceFacets["Wholesale Price"],
283
321
  "WWHL": data.sku[count].priceFacets["Wholesale Price"]
284
322
  },
@@ -292,19 +330,7 @@ const ProductData = {
292
330
  "WADW": data.sku[count].priceFacets.PV,
293
331
  "WHL": data.sku[count].priceFacets.PV
294
332
  },
295
- "orderTypes": {
296
- "adr": true,
297
- "order": true,
298
- "zpfc": false,
299
- "zadp": true,
300
- "ars": true,
301
- "kiosk": true,
302
- "mobile": true,
303
- "preferred customer": true,
304
- "retail": true,
305
- "web": true,
306
- "web display": true
307
- },
333
+ "orderTypes": this._setOrderType(data.sku[count].properties),
308
334
  "childSkus": [],
309
335
  "custTypes": this.switchCustType(data.properties.customerTypes),
310
336
  "division": data.properties.division,
@@ -322,14 +348,14 @@ const ProductData = {
322
348
  "variantsLabel": data.sku[count].properties.variantLabel || "",
323
349
  "groupOffer": false,
324
350
  "personalOffer": false,
325
- "savedEventName": null,
326
- "salesLabel": "",
327
- "eventName": null,
351
+ "savedEventName": eventName,
352
+ "salesLabel": eventLabels,
353
+ "eventName": eventName,
328
354
  "sizeWeight": '',
329
355
  "nettoWeight": "",
330
356
  "variants": variants,
331
357
  "searchScore": 0,
332
- "isExclusive": data.sku[count].properties.isExclusive || false,
358
+ "isExclusive": data.sku[count].properties.isExclusive,
333
359
  "marketAttributes": {
334
360
  "discount": true,
335
361
  "redeem": true,
@@ -337,15 +363,15 @@ const ProductData = {
337
363
  },
338
364
  "restrictedMarkets": [],
339
365
  "addOns": [],
340
- "inventory": data.sku[count].inventory || "" //inventory label
341
-
366
+ "inventory": data.sku[count].inventory || "", //inventory label
367
+ "equinoxProductId": data.identifier
342
368
  };
343
369
  let newProduct = new Product(prod);
344
370
  return newProduct
345
- })
371
+ });
346
372
 
347
373
  let data = {
348
- products: prodArr,
374
+ products: this._sortProductsBySku(skus, prodArr),
349
375
  count: productDataResponse.length
350
376
  };
351
377
  return {
@@ -358,29 +384,27 @@ const ProductData = {
358
384
  },
359
385
 
360
386
  switchStatusFromEquinox: function (status) {
361
- const { equinoxStatus } = ProductStatus;
362
387
  let newStatus = '';
363
- switch (status.toLowerCase()) {
364
- case equinoxStatus.SELLABLE:
365
- newStatus = ProductStatus.ReleasedForSale;
388
+ switch (status) {
389
+ case 'Sellable':
390
+ newStatus = 'RELEASED_FOR_SALE';
366
391
  break;
367
- case equinoxStatus.PREVIEW_PRODUCT:
368
- newStatus = ProductStatus.NotReleasedForSale;
392
+ case 'Preview product':
393
+ newStatus = 'NOT_RELEASED_FOR_SALE';
369
394
  break;
370
- case equinoxStatus.DISCONTINUED:
371
- newStatus = ProductStatus.Discontinued;
395
+ case 'Discontinued':
396
+ newStatus = 'DISCONTINUED';
372
397
  break;
373
- case equinoxStatus.STOPPED:
374
- newStatus = ProductStatus.Discontinued;
398
+ case 'Stopped':
399
+ newStatus = 'DISCONTINUED';
375
400
  break;
376
- case equinoxStatus.REPLACEMENT:
377
- newStatus = ProductStatus.NotReleasedForSale;
401
+ case 'Replacement':
402
+ newStatus = 'NOT_RELEASED_FOR_SALE';
378
403
  break;
379
404
  default:
380
- newStatus = ProductStatus.NotReleasedForSale;
405
+ newStatus = 'NOT_RELEASED_FOR_SALE'
381
406
  break;
382
407
  }
383
-
384
408
  return newStatus;
385
409
  },
386
410
 
@@ -389,33 +413,92 @@ const ProductData = {
389
413
  * @param {*} custType
390
414
  *
391
415
  */
416
+ switchCustType: function (custType) {
417
+ let newCustType = [];
418
+ if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
419
+ newCustType.push(10)
420
+ if (custType.includes('Retail Customer'))
421
+ newCustType.push(20)
422
+ if (custType.includes('Preferred Customer/Member'))
423
+ newCustType.push(30)
424
+ return newCustType.toString()
425
+ },
392
426
 
393
427
  /**
394
- * map customer types from string to code
395
- * @param {*} eqCustomerTypes
396
- * @returns
428
+ * Sorts the product by sku
429
+ * @param {Array} skus - the skus arrangment which the sorting will base out of
430
+ * @param {Array} products - this products to be sorted
397
431
  */
398
- switchCustType: function (eqCustomerTypes) {
399
- if (!eqCustomerTypes) {
400
- return "";
401
- }
402
432
 
403
- const custTypes = eqCustomerTypes.split(',').map(customerType => customerType.toLowerCase());
433
+ _sortProductsBySku: function (skus, products) {
404
434
 
405
- let newCustType = [];
406
- if (custTypes.includes(CustomerTypes.BrandAffiliate)) {
407
- newCustType.push(CustomerTypes.properties.BRAND_AFFILIATE.code);
435
+ if(!skus || !products || products.length === 1) {
436
+ return products
408
437
  }
409
438
 
410
- if (custTypes.includes(CustomerTypes.Retail)) {
411
- newCustType.push(CustomerTypes.properties.RETAIL.code);
412
- }
439
+ const sortedProducts = products.sort(function (a, b) {
440
+ return skus.indexOf(a.sku) - skus.indexOf(b.sku);
441
+ });
413
442
 
414
- if (custTypes.includes(CustomerTypes.Preferred) || custTypes.includes(CustomerTypes.PreferredCustomer)) {
415
- newCustType.push(CustomerTypes.properties.PREFERRED.code);
416
- }
443
+ return sortedProducts
417
444
 
418
- return newCustType.toString()
445
+ },
446
+
447
+ /**
448
+ *
449
+ * @param {*} availableChannels
450
+ *
451
+ * This function is use to convert arsPhone,web,kiosk,mobile,subscription
452
+ * to orderType object
453
+ * "adr”
454
+ "order"
455
+ "zpfc"
456
+ "zadp"
457
+ "ars"
458
+ "kiosk"
459
+ "mobile"
460
+ "preferred customer"
461
+ "retail"
462
+ "web"
463
+ "web display"
464
+ */
465
+ _setOrderType: function (properties) {
466
+ let orderTypeArr = {
467
+ "adr": false,
468
+ "order": false,
469
+ "zpfc": false,
470
+ "zadp": false,
471
+ "ars": false,
472
+ "kiosk": false,
473
+ "mobile": false,
474
+ "preferred customer": false,
475
+ "retail": false,
476
+ "web": false,
477
+ "web display": false
478
+ };
479
+ let availableChannelsArr = properties.availableChannels.split(',')
480
+
481
+ availableChannelsArr.forEach(channel => {
482
+ if (channel == 'arsPhone')
483
+ orderTypeArr.ars = true
484
+ if (channel == 'web') {
485
+ orderTypeArr.order = true
486
+ orderTypeArr.web = true
487
+ }
488
+ if (channel == 'kiosk')
489
+ orderTypeArr.kiosk = true
490
+ if (channel == 'mobile')
491
+ orderTypeArr.mobile = true
492
+ if (channel == 'subscription')
493
+ orderTypeArr.adr = true
494
+
495
+ });
496
+ if (properties.retail)
497
+ orderTypeArr.retail = true
498
+ if (properties.prefferredCustomer)
499
+ orderTypeArr['preferred customer'] = true
500
+
501
+ return orderTypeArr;
419
502
  }
420
503
  }
421
504
 
@@ -17,13 +17,6 @@ const ProductStatus = {
17
17
  STOP_STATUS: { stringKey: "stopStatus", code: 5 },
18
18
  NOT_FOUND: { stringKey: "", code: 0 },
19
19
  NOT_SOLD_SEPERATELY: {stringKey: "notSoldSeperately", code: 4 }
20
- },
21
- equinoxStatus: {
22
- SELLABLE: 'sellable',
23
- PREVIEW_PRODUCT: 'preview product',
24
- DISCONTINUED: 'discontinued',
25
- STOPPED: 'stopped',
26
- REPLACEMENT: 'Replacement'
27
20
  }
28
21
  };
29
22
 
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- const CustomerTypes = {
4
- BrandAffiliate: "brandaffiliate",
5
- Preferred: "preferred",
6
- PreferredCustomer: "preferred customer",
7
- Retail: "retail",
8
- properties: {
9
- BRAND_AFFILIATE: { stringKey: "DIST", code: 10 },
10
- RETAIL: { stringKey: "CUST", code: 20 },
11
- PREFERRED: { stringKey: "preferred", code: 30 },
12
- PREFERRED_CUSTOMER: { stringKey: "PREF", code: 30 }
13
- }
14
- };
15
-
16
- module.exports = CustomerTypes;