@nuskin/ns-product-lib 2.5.0-cx24-3175.2 → 2.5.0-cx24-2179.2.13

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,18 +1,130 @@
1
- # [2.5.0-cx24-3175.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-3175.1...v2.5.0-cx24-3175.2) (2023-01-20)
1
+ # [2.5.0-cx24-2179.2.13](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.12...v2.5.0-cx24-2179.2.13) (2023-01-23)
2
+
3
+
4
+ ### Fix
5
+
6
+ * undefined value of the URL (CX24-3122,CX24-3234) ([1ea65a7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/1ea65a7cf8249dfa4a378a66e74823aca76f5566))
7
+
8
+ # [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)
9
+
10
+
11
+ ### Fix
12
+
13
+ * 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))
14
+
15
+ # [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)
16
+
17
+
18
+ ### Fix
19
+
20
+ * Equinox API called for non equinox market ([50eaa48](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/50eaa48a41a9e00d48ff79de35b955b817c4c0ea))
21
+
22
+ # [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)
23
+
24
+
25
+ ### Fix
26
+
27
+ * 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))
28
+
29
+ # [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)
30
+
31
+
32
+ ### Fix
33
+
34
+ * 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)
35
+ * 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))
36
+ * Unit Tests ([ace52c6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ace52c6418991d0263a1e1f8d99901e724abf923))
37
+
38
+ ### Release
39
+
40
+ * Automated changes by GitLab pipeline [skip ci] ([eb755fa](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/eb755fae1e1f1f221a34d92f5ff4e64787a4132d))
41
+ * Automated changes by GitLab pipeline [skip ci] ([6a75f7a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/6a75f7a5f8b2f3b17e4d7387af37cad4f367b45c))
42
+
43
+ ### Update
44
+
45
+ * 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))
46
+
47
+ # [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)
48
+
49
+ * 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)
50
+
51
+ # [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)
52
+
53
+
54
+ ### New
55
+
56
+ * 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)
57
+
58
+ # [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)
59
+
60
+
61
+ ### New
62
+
63
+ * 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)
64
+
65
+ # [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)
66
+
67
+
68
+ ### New
69
+
70
+ * 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)
71
+
72
+ # [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)
73
+
74
+
75
+ ### New
76
+
77
+ * 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)
78
+
79
+ # [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)
80
+
81
+
82
+ ### New
83
+
84
+ * 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)
85
+
86
+ # [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)
87
+ >>>>>>> CX24.2
88
+
89
+
90
+ ### Fix
91
+
92
+ * [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))
93
+
94
+ ### Release
95
+
96
+ * Automated changes by GitLab pipeline [skip ci] ([07bfa40](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/07bfa404c552c05637c2c8a537c4ff298536874e))
97
+ * Automated changes by GitLab pipeline [skip ci] ([fa1c0d9](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/fa1c0d9d5853482e3ac49cea4e99599e7192f85b))
98
+ * Automated changes by GitLab pipeline [skip ci] ([2d20787](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/2d2078763b2d57edb8a24f438ac90dd37c3ff41b))
99
+
100
+ ### Update
101
+
102
+ * set ADR pricing from equinox (CX24-2862) ([65d04d2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/65d04d2e9ff4018edfe99e5a7412bee985d3def2))
103
+ * set ADR pricing from equinox (CX24-2862) ([54a5693](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/54a56932e5df36c9c30ce6358d8597c98be3d20d))
104
+ * set ADR pricing from equinox (CX24-2862) ([bbd135f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bbd135f1ed0395c578be2274c84ba136ceed9376))
105
+ * set ADR pricing from equinox (CX24-2862) ([197003e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/197003e1629bd394c547a118d332b5e8574dfc7d))
106
+
107
+ # [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)
2
108
 
3
109
 
4
110
  ### Update
5
111
 
6
- * remapped custType field in variant (#CX24-3175) ([2e4c70a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/2e4c70aa2bf8d2f386a4d083e74f47ae141cdf54)), 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) ([b64dcea](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b64dcea4dd3374be992c667db5c0b2604aacc029))
7
113
 
8
- # [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)
114
+ # [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)
9
115
 
10
116
 
11
117
  ### Update
12
118
 
13
- * 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)
14
- * 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)
15
- * 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)
119
+ * set ADR pricing from equinox (CX24-2862) ([9f6dfb7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9f6dfb726f40b1335411318629a2ebdf1b4dac96))
120
+ * set ADR pricing from equinox (CX24-2862) ([61f550a](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/61f550a21c5cc9d062549ec2aaf2758aebccf2be))
121
+
122
+ ## [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)
123
+
124
+
125
+ ### Fix
126
+
127
+ * [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))
16
128
 
17
129
  ## [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)
18
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.5.0-cx24-3175.2",
3
+ "version": "2.5.0-cx24-2179.2.13",
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
+ console.trace(config);
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.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.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,20 +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
- },
182
- "custTypes": this.switchCustType(eqVariant.properties.customerTypes),
178
+ "orderTypes": this._setOrderType(eqVariant.properties),
183
179
  "division": eqVariant.properties.division,
184
180
  "backOrderDate": null,
185
181
  "locallyProduced": false,
@@ -190,29 +186,65 @@ const ProductData = {
190
186
  "shade": "",
191
187
  "status": this.switchStatusFromEquinox(eqVariant.properties.status),
192
188
  "variantType": "Other",
193
- "variantDropdownLabel": eqVariant.properties.variantSelectLabel || "",
189
+ "variantDropdownLabel": eqVariant.properties.variantLabel || "",
194
190
  "variantDropdownPlaceholder": "Select Type",
195
- "variantsLabel": eqVariant.properties.variantSelectLabel || "",
191
+ "variantsLabel": eqVariant.properties.variantLabel || "",
196
192
  "groupOffer": false,
197
193
  "personalOffer": false,
198
- "savedEventName": null,
199
- "salesLabel": "",
200
- "eventName": null,
194
+ "savedEventName": eventName,
195
+ "salesLabel": eventLabels,
196
+ "eventName": eventName,
201
197
  "sizeWeight": '',
202
198
  "nettoWeight": "",
203
199
  "searchScore": 0,
204
- "isExclusive": eqVariant.properties.isExclusive || false,
200
+ "isExclusive": false,
205
201
  "marketAttributes": {
206
202
  "discount": true,
207
203
  "redeem": true,
208
204
  "earn": true
209
205
  },
210
206
  "restrictedMarkets": [],
211
- "addOns": []
207
+ "addOns": [],
208
+ "equinoxProductId": eqVariant.identifier
212
209
  };
213
210
  },
214
211
 
215
- 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) {
216
248
  let prod = [];
217
249
  let count = 0;
218
250
  let variants = {};
@@ -229,12 +261,17 @@ const ProductData = {
229
261
  }
230
262
 
231
263
  if (data.sku && data.sku.length > 1) {
232
- data.sku.map(variant => {
264
+ //exclude base product from variants
265
+ data.sku.filter(v => v.identifier.substring(2, 4) !== "55").map(variant => {
233
266
  variants[variant.identifier] = this.eqProductVariantMapper(variant);
234
267
  return variant;
235
268
  });
236
269
  }
237
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
+
238
275
  prod = {
239
276
  "sku": data.sku[count].identifier,
240
277
  "globalProductID": data.identifier,
@@ -273,13 +310,13 @@ const ProductData = {
273
310
  "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
274
311
  "pv": data.sku[count].priceFacets.PV,
275
312
  "priceType": "WRTL",
276
- "price": data.sku[count].priceFacets["Regular Price"],
313
+ "price": discountedPrice,
277
314
  "priceMap": {
278
- "WRTL": data.sku[count].priceFacets["Regular Price"],
315
+ "WRTL": productPrice,
279
316
  "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
280
- "WADR": 9999.01,
317
+ "WADR": data.sku[count].priceFacets["Regular Price"],
281
318
  "RTL": data.sku[count].priceFacets["Regular Price"],
282
- "WADW": 9998.01,
319
+ "WADW": data.sku[count].priceFacets["Wholesale Price"],
283
320
  "WHL": data.sku[count].priceFacets["Wholesale Price"],
284
321
  "WWHL": data.sku[count].priceFacets["Wholesale Price"]
285
322
  },
@@ -293,19 +330,7 @@ const ProductData = {
293
330
  "WADW": data.sku[count].priceFacets.PV,
294
331
  "WHL": data.sku[count].priceFacets.PV
295
332
  },
296
- "orderTypes": {
297
- "adr": true,
298
- "order": true,
299
- "zpfc": false,
300
- "zadp": true,
301
- "ars": true,
302
- "kiosk": true,
303
- "mobile": true,
304
- "preferred customer": true,
305
- "retail": true,
306
- "web": true,
307
- "web display": true
308
- },
333
+ "orderTypes": this._setOrderType(data.sku[count].properties),
309
334
  "childSkus": [],
310
335
  "custTypes": this.switchCustType(data.properties.customerTypes),
311
336
  "division": data.properties.division,
@@ -323,14 +348,14 @@ const ProductData = {
323
348
  "variantsLabel": data.sku[count].properties.variantLabel || "",
324
349
  "groupOffer": false,
325
350
  "personalOffer": false,
326
- "savedEventName": null,
327
- "salesLabel": "",
328
- "eventName": null,
351
+ "savedEventName": eventName,
352
+ "salesLabel": eventLabels,
353
+ "eventName": eventName,
329
354
  "sizeWeight": '',
330
355
  "nettoWeight": "",
331
356
  "variants": variants,
332
357
  "searchScore": 0,
333
- "isExclusive": data.sku[count].properties.isExclusive || false,
358
+ "isExclusive": data.sku[count].properties.isExclusive,
334
359
  "marketAttributes": {
335
360
  "discount": true,
336
361
  "redeem": true,
@@ -338,15 +363,15 @@ const ProductData = {
338
363
  },
339
364
  "restrictedMarkets": [],
340
365
  "addOns": [],
341
- "inventory": data.sku[count].inventory || "" //inventory label
342
-
366
+ "inventory": data.sku[count].inventory || "", //inventory label
367
+ "equinoxProductId": data.identifier
343
368
  };
344
369
  let newProduct = new Product(prod);
345
370
  return newProduct
346
- })
371
+ });
347
372
 
348
373
  let data = {
349
- products: prodArr,
374
+ products: this._sortProductsBySku(skus, prodArr),
350
375
  count: productDataResponse.length
351
376
  };
352
377
  return {
@@ -359,29 +384,27 @@ const ProductData = {
359
384
  },
360
385
 
361
386
  switchStatusFromEquinox: function (status) {
362
- const { equinoxStatus } = ProductStatus;
363
387
  let newStatus = '';
364
- switch (status.toLowerCase()) {
365
- case equinoxStatus.SELLABLE:
366
- newStatus = ProductStatus.ReleasedForSale;
388
+ switch (status) {
389
+ case 'Sellable':
390
+ newStatus = 'RELEASED_FOR_SALE';
367
391
  break;
368
- case equinoxStatus.PREVIEW_PRODUCT:
369
- newStatus = ProductStatus.NotReleasedForSale;
392
+ case 'Preview product':
393
+ newStatus = 'NOT_RELEASED_FOR_SALE';
370
394
  break;
371
- case equinoxStatus.DISCONTINUED:
372
- newStatus = ProductStatus.Discontinued;
395
+ case 'Discontinued':
396
+ newStatus = 'DISCONTINUED';
373
397
  break;
374
- case equinoxStatus.STOPPED:
375
- newStatus = ProductStatus.Discontinued;
398
+ case 'Stopped':
399
+ newStatus = 'DISCONTINUED';
376
400
  break;
377
- case equinoxStatus.REPLACEMENT:
378
- newStatus = ProductStatus.NotReleasedForSale;
401
+ case 'Replacement':
402
+ newStatus = 'NOT_RELEASED_FOR_SALE';
379
403
  break;
380
404
  default:
381
- newStatus = ProductStatus.NotReleasedForSale;
405
+ newStatus = 'NOT_RELEASED_FOR_SALE'
382
406
  break;
383
407
  }
384
-
385
408
  return newStatus;
386
409
  },
387
410
 
@@ -390,33 +413,92 @@ const ProductData = {
390
413
  * @param {*} custType
391
414
  *
392
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
+ },
393
426
 
394
427
  /**
395
- * map customer types from string to code
396
- * @param {*} eqCustomerTypes
397
- * @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
398
431
  */
399
- switchCustType: function (eqCustomerTypes) {
400
- if (!eqCustomerTypes) {
401
- return "";
402
- }
403
432
 
404
- const custTypes = eqCustomerTypes.split(',').map(customerType => customerType.toLowerCase());
433
+ _sortProductsBySku: function (skus, products) {
405
434
 
406
- let newCustType = [];
407
- if (custTypes.includes(CustomerTypes.BrandAffiliate)) {
408
- newCustType.push(CustomerTypes.properties.BRAND_AFFILIATE.code);
435
+ if(!skus || !products || products.length === 1) {
436
+ return products
409
437
  }
410
438
 
411
- if (custTypes.includes(CustomerTypes.Retail)) {
412
- newCustType.push(CustomerTypes.properties.RETAIL.code);
413
- }
439
+ const sortedProducts = products.sort(function (a, b) {
440
+ return skus.indexOf(a.sku) - skus.indexOf(b.sku);
441
+ });
414
442
 
415
- if (custTypes.includes(CustomerTypes.Preferred) || custTypes.includes(CustomerTypes.PreferredCustomer)) {
416
- newCustType.push(CustomerTypes.properties.PREFERRED.code);
417
- }
443
+ return sortedProducts
418
444
 
419
- 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;
420
502
  }
421
503
  }
422
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;