@nuskin/ns-product-lib 2.4.0-cx24-2462.1.1 → 2.4.0-cx24-2462.2.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,10 +1,92 @@
1
- # [2.4.0-cx24-2462.1.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.4.0-cx24-2462.1.1) (2022-10-20)
1
+ # [2.4.0-cx24-2462.2.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.0-cx24-2462.1.1...v2.4.0-cx24-2462.2.1) (2022-11-15)
2
+
3
+
4
+ ### Fix
5
+
6
+ * [Equinox market] Admin > Move up/down/top/bottom of featured products and edit bundle is not working ([0077fdc](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/0077fdc034257bb67b4ea8e49b7e0f55abedb292))
7
+ * platform agnostic updates to ns-product-lib ([bb33b74](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/bb33b7493530b88cb34ed6e0c9428f99f5818644))
8
+ * platform agnostic updates to ns-product-lib ([50ec0a0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/50ec0a0797e30b79c3d7f7a254ac9417cf935322))
9
+
10
+ ### New
11
+
12
+ * added support for inventory label (#CX24-2186) ([684cebe](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/684cebe2d743f4d24310eb2b464c3fa90aa914a8)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
13
+
14
+ ### Release
15
+
16
+ * Automated changes by GitLab pipeline [skip ci] ([990dab6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/990dab6750a79b1b8c85ea6e11fa0dfe2c032574))
17
+ * Automated changes by GitLab pipeline [skip ci] ([2b8cea7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/2b8cea79b743101860eb8ee5232bd41f97e38c23))
18
+ * Automated changes by GitLab pipeline [skip ci] ([b6fdc37](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b6fdc37f4c612ca6ccec378e571ab72f7b41ec24))
19
+
20
+ ### Update
21
+
22
+ * added support for variant and price (#CX24-2186) ([5d2b029](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/5d2b029f3961c4fc82d83edd920195b493c8c551)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
23
+ * added variant label (#CX24-2186) ([75aaa1e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/75aaa1e57b029c39dbf8a408760d289fcf172044)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
24
+ * map remaining equinox properties (CX24-2462) ([c0b4584](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/c0b45848e6e1b4b38de6e2755c1592e6429d1da9))
25
+ * map remaining equinox properties (CX24-2462) ([29a73ff](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/29a73ffddf056d6bad14cb9b8587c790677ae955))
26
+ * map remaining equinox properties (CX24-2462) ([dafe0c0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/dafe0c0349207439d05ba0e45a71c8868a1d65bc))
27
+
28
+ # [2.5.0-fix.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-fix.1...v2.5.0-fix.2) (2022-11-04)
29
+
30
+
31
+ ### Fix
32
+
33
+ * update inventory label to match with master ([005b52c](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/005b52cd10063d9af6975315f37d8995d630eb66))
34
+
35
+ # [2.5.0-fix.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.4.0...v2.5.0-fix.1) (2022-11-04)
36
+
37
+
38
+ ### Fix
39
+
40
+ * use platform-specific values when initialized ([04d9c5e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/04d9c5eb555b6a8304329ac63f1304dd61e5ecd2))
41
+
42
+ ### New
43
+
44
+ * added support for inventory label (#CX24-2186) ([78e9385](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/78e9385432b6c8245061a450021fe9dd9da9b840)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
45
+
46
+ ### Release
47
+
48
+ * Automated changes by GitLab pipeline [skip ci] ([78b03b1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/78b03b1c22a09c29c39b926696f2e2141a1ecd1e))
49
+
50
+ ## [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)
51
+
52
+
53
+ ### Fix
54
+
55
+ * platform agnostic updates to ns-product-lib ([d53659f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/d53659f20ab708b1212dd5820be9321e6d1855a5))
56
+
57
+ # [2.4.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.4.0) (2022-10-26)
58
+ ## [2.3.1-fix.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.3.1-fix.1) (2022-11-04)
59
+ # [2.4.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.4.0) (2022-10-26)
2
60
 
3
61
 
4
62
  ### Fix
5
63
 
6
64
  * To make multiple products work (#CX24-2444) ([ce4c483](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ce4c483b7fbb0527e60045d8174fd503a67e63fa)), closes [#CX24-2444](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2444)
7
65
 
66
+ ### New
67
+
68
+ * added support for inventory label (#CX24-2186) ([3e27481](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3e2748106cd6098086dbd6b738964deabacc875d)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
69
+
70
+ ### Release
71
+
72
+ * Automated changes by GitLab pipeline [skip ci] ([8f75316](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/8f75316b692ddccda5b7bea830ee6dc625b942c7))
73
+ * Automated changes by GitLab pipeline [skip ci] ([36dca5b](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/36dca5b92285ae6d8ae96345256df92102efad8e))
74
+
75
+ ### Update
76
+
77
+ * added support for variant and price (#CX24-2186) ([e0bf8f2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e0bf8f280a838dfa4cc613e5bc34d254dbdc8e1a)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
78
+ * added variant label (#CX24-2186) ([4c223b3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/4c223b34438ed73cb824716cacb93482486f8195)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
79
+ <<<<<<< HEAD
80
+ <<<<<<< HEAD
81
+ =======
82
+ >>>>>>> d53659f (Fix: platform agnostic updates to ns-product-lib)
83
+ * use platform-specific values when initialized ([18de006](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/18de006211ab396f4d7fa40d0089c8e185d9cee9))
84
+ * To make multiple products work (#CX24-2444) ([ce4c483](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ce4c483b7fbb0527e60045d8174fd503a67e63fa)), closes [#CX24-2444](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2444)
85
+
86
+ ### New
87
+
88
+ * added support for inventory label (#CX24-2186) ([3e27481](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3e2748106cd6098086dbd6b738964deabacc875d)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
89
+
8
90
  ### Release
9
91
 
10
92
  * Automated changes by GitLab pipeline [skip ci] ([8f75316](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/8f75316b692ddccda5b7bea830ee6dc625b942c7))
@@ -12,7 +94,13 @@
12
94
 
13
95
  ### Update
14
96
 
15
- * map product images to carousel images (CX24-2462) ([1e17c6e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/1e17c6ec39e54b4bdb2bb804c997eb14c9e501d5))
97
+ * added support for variant and price (#CX24-2186) ([e0bf8f2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e0bf8f280a838dfa4cc613e5bc34d254dbdc8e1a)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
98
+ * added variant label (#CX24-2186) ([4c223b3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/4c223b34438ed73cb824716cacb93482486f8195)), closes [#CX24-2186](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2186)
99
+ <<<<<<< HEAD
100
+ =======
101
+ >>>>>>> db13945 (Release: Automated changes by GitLab pipeline [skip ci])
102
+ =======
103
+ >>>>>>> d53659f (Fix: platform agnostic updates to ns-product-lib)
16
104
 
17
105
  # [2.3.0](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.2.0...v2.3.0) (2022-10-14)
18
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.4.0-cx24-2462.1.1",
3
+ "version": "2.4.0-cx24-2462.2.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": {
@@ -19,13 +19,14 @@
19
19
  "license": "ISC",
20
20
  "homepage": "https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/blob/master/README.md",
21
21
  "devDependencies": {
22
+ "axios-mock-adapter": "1.21.2",
22
23
  "eslint": "5.16.0",
23
24
  "eslint-config-google": "0.14.0",
24
25
  "eslint-config-prettier": "4.1.0",
25
26
  "eslint-plugin-json": "2.1.1",
26
27
  "eslint-plugin-prettier": "3.1.2",
27
- "axios-mock-adapter": "1.18.2",
28
- "jest": "25.1.0",
28
+ "jest": "26.0.1",
29
+ "jest-environment-jsdom": "26.0.1",
29
30
  "jest-sonar-reporter": "2.0.0",
30
31
  "prettier": "1.19.1"
31
32
  },
@@ -4,14 +4,51 @@ const { getEnvironmentFromUrl } = require('@nuskin/ns-common-lib');
4
4
  const config = require('./environment');
5
5
 
6
6
  // contentstack HTTP service
7
- const env = getEnvironmentFromUrl(window.location.host);
8
- const envConfig = config.getCredentials(env);
9
- const baseURL = `${envConfig.url}/stacks/${envConfig.apiKey}?environment=${envConfig.env}`;
10
- const headers = {
11
- 'access_token': `${envConfig.accessToken}`,
12
- 'Content-Type': 'application/json'
13
- };
14
- const http = axios.create({ baseURL, headers });
7
+ const platform = usePlatformSpecificVariables();
8
+ const http = axios.create({ baseURL: platform.baseURL, headers: platform.headers });
9
+
10
+ // usePlatformVariables returns an object with platform-specific values; defaults to Lambda environment
11
+ function usePlatformSpecificVariables() {
12
+ if (typeof window !== 'undefined') {
13
+ return useWebEnvironment();
14
+ }
15
+
16
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
17
+ return useMobileEnvironment();
18
+ }
19
+
20
+ return useLambdaEnvironment();
21
+ }
22
+
23
+ function useWebEnvironment() {
24
+ console.log('web');
25
+ const env = getEnvironmentFromUrl(window.location.host);
26
+ const envConfig = config.getCredentials(env);
27
+ const baseURL = `${envConfig.url}/stacks/${envConfig.apiKey}?environment=${envConfig.env}`;
28
+ const headers = {
29
+ 'access_token': `${envConfig.accessToken}`,
30
+ 'Content-Type': 'application/json'
31
+ };
32
+
33
+ return { baseURL, env, headers }
34
+ }
35
+
36
+ function useMobileEnvironment() {
37
+ // ...
38
+ }
39
+
40
+ function useLambdaEnvironment() {
41
+ console.log('lambda');
42
+ const env = {};
43
+ const baseURL = `contentstack-call-for-lambda`;
44
+ const headers = {
45
+ 'access_token': `contentstack-access-token-for-lambda`,
46
+ 'Content-Type': 'application/json'
47
+ };
48
+
49
+ return { baseURL, env, headers }
50
+ }
51
+
15
52
 
16
53
  // in-memory caching
17
54
  const cacheKeys = { aemConfig: 'aemConfig', equinoxMarkets: 'equinoxMarkets', kongUrl: 'kongUrl' };
@@ -19,7 +56,7 @@ const cacheTTLInSeconds = 30 * 1000;
19
56
  const cache = {
20
57
  [cacheKeys.aemConfig]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
21
58
  [cacheKeys.equinoxMarkets]: { data: null, ttl: Date.now() + cacheTTLInSeconds },
22
- [cacheKeys.kongUrl]: { data: null, ttl: Date.now() + cacheTTLInSeconds}
59
+ [cacheKeys.kongUrl]: { data: null, ttl: Date.now() + cacheTTLInSeconds }
23
60
  };
24
61
 
25
62
  /**
@@ -67,7 +104,7 @@ function getCachedData(key) {
67
104
  async function getAEMConfig() {
68
105
  try {
69
106
  if (isCacheExpired(cacheKeys.aemConfig)) {
70
- const marketConfig = `market_config_${env}`;
107
+ const marketConfig = `market_config_${platform.env}`;
71
108
  const variables = { uid: 'blt52b0b83a89763791' };
72
109
  const query = `query AemConfigByUid($uid: String!) {
73
110
  aem_config(uid: $uid) {
@@ -114,7 +151,7 @@ async function getAEMConfig() {
114
151
  async function getEquinoxMarkets() {
115
152
  try {
116
153
  if (isCacheExpired(cacheKeys.equinoxMarkets)) {
117
- const marketConfig = `${env}_markets`;
154
+ const marketConfig = `${platform.env}_markets`;
118
155
  const variables = { uid: 'blt5633ff9e560f14ef' };
119
156
  const query = `query EquinoxMarketsByUid($uid: String!) {
120
157
  equinox_markets(uid: $uid) {
@@ -151,7 +188,7 @@ async function getKongUrl() {
151
188
  const query = `query KongUrlByUid($uid: String!) {
152
189
  equinox_markets(uid: $uid) {
153
190
  kong_urls {
154
- ${env}
191
+ ${platform.env}
155
192
  }
156
193
  }
157
194
  }`;
@@ -160,9 +197,9 @@ async function getKongUrl() {
160
197
  data: { variables, query }
161
198
  });
162
199
 
163
- setCachedData(cacheKeys.kongUrl, data.equinox_markets.kong_urls[env]);
200
+ setCachedData(cacheKeys.kongUrl, data.equinox_markets.kong_urls[platform.env]);
164
201
  }
165
-
202
+
166
203
  return getCachedData(cacheKeys.kongUrl);
167
204
  } catch (error) {
168
205
  console.error(error);
@@ -199,6 +236,7 @@ async function contentstackService(config) {
199
236
 
200
237
  try {
201
238
  const response = await http.post('', data);
239
+ console.log(response);
202
240
  return response.data
203
241
  } catch (error) {
204
242
  console.error(error.response.data.errors);
package/src/product.js CHANGED
@@ -72,6 +72,10 @@ const Product = function(productData) {
72
72
  // agelocme stuff
73
73
  this.agelocme = null; // object containing agelocme information (like code, label, name)
74
74
 
75
+ //equinox inventory / stock label
76
+ //@example "IN STOCK"
77
+ this.inventory = "";
78
+
75
79
  this.setMarketAttributes = function(productStatus) {
76
80
  if (productStatus.marketAttributes) {
77
81
  this.marketAttributes = productStatus.marketAttributes;
@@ -518,6 +522,7 @@ const Product = function(productData) {
518
522
  retData.marketAttributes = this.marketAttributes;
519
523
  retData.restrictedMarkets = this.restrictedMarkets;
520
524
  retData.addOns = this.addOns;
525
+ retData.inventory = this.inventory;
521
526
 
522
527
  return retData;
523
528
  };
@@ -626,6 +631,7 @@ const Product = function(productData) {
626
631
  this.marketAttributes = productData.marketAttributes;
627
632
  this.addOns = productData.addOns || [];
628
633
  this.restrictedMarkets = productData.restrictedMarkets || [];
634
+ this.inventory = productData.inventory || "";
629
635
 
630
636
  if (data.priceType) {
631
637
  this.addPricing(data.priceType, data.price);
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  const axios = require("axios");
3
3
  const contentstack = require('./contentstack/contentstack');
4
- const product = require("./product");
4
+ const Product = require("./product");
5
5
 
6
6
  /** @type {*} */
7
7
  const ProductData = {
8
8
  /**
9
- * @param {string[]} skus
10
- * @param {string} locale
11
- * @param {string} market
12
- * @param {boolean} isEquinoxEnabled
9
+ * @param {string[]} skus
10
+ * @param {string} locale
11
+ * @param {string} market
12
+ * @param {boolean} isEquinoxEnabled
13
13
  */
14
14
  getProductData: async function (skus, locale, market, isEquinoxEnabled = false) {
15
15
  const localeMarket = `${locale}_${market}`;
@@ -28,9 +28,8 @@ const ProductData = {
28
28
  getProductFromEquinox: async function (skus, locale, storeID) {
29
29
  const filter = '{"filters":[{"field":"index_key_skuId","operation":"IN","value":"' + skus.toString() + '"}]}';
30
30
  axios.defaults.withCredentials = true;
31
-
31
+
32
32
  const url = await contentstack.getKongUrl() + `/orchestrationservices/storefront/catalogs/search/`;
33
- console.log("Dynamic URL", url)
34
33
  const href = `${url}?filter=${encodeURI(filter)}`;
35
34
  const response = await axios.request({
36
35
  method: 'get',
@@ -44,7 +43,7 @@ const ProductData = {
44
43
  });
45
44
 
46
45
  if (response.data.product) {
47
- return this.eqProductMapper(response.data.product);
46
+ return this.eqProductMapper(response.data.product, skus);
48
47
  }
49
48
 
50
49
  return {
@@ -78,11 +77,11 @@ const ProductData = {
78
77
  responseType: 'json'
79
78
  });
80
79
  },
81
-
80
+
82
81
  /**
83
82
  * @param {contentstack.MarketConfig} marketConfig
84
83
  */
85
- getLegacyRequestHeaders: function(marketConfig) {
84
+ getLegacyRequestHeaders: function (marketConfig) {
86
85
  return {
87
86
  'Content-Type': 'application/json',
88
87
  client_id: marketConfig.checkout_client_id,
@@ -90,21 +89,149 @@ const ProductData = {
90
89
  };
91
90
  },
92
91
 
93
- eqProductMapper: function (productDataResponse) {
92
+ /**
93
+ * Map product variant
94
+ * @todo remove unnecessary fields
95
+ * @param {*} eqVariant
96
+ * @returns Array<Product>
97
+ */
98
+ eqProductVariantMapper: function (eqVariant) {
99
+
100
+ let imageURL = eqVariant.properties.imageURL;
101
+ const regex = /\d+.\d+/
102
+ let thumbnailImage = ''
103
+
104
+ if (imageURL.includes('contentstack')) {
105
+ thumbnailImage = imageURL + '?width=40'
106
+ } else {
107
+ thumbnailImage = imageURL.replace(regex, '40.40')
108
+ }
109
+
110
+ return {
111
+ "sku": eqVariant.identifier,
112
+ "globalProductID": eqVariant.identifier,
113
+ "title": eqVariant.properties.name,
114
+ "country": eqVariant.properties.market,
115
+ "language": "en",
116
+ "shortDescr": eqVariant.properties.description,
117
+ "longDescr": eqVariant.properties.productDetailsDescription,
118
+ "fullImage": imageURL,
119
+ "imageAltText": eqVariant.properties.name,
120
+ "productCarouselImages": [
121
+ {
122
+ "contentType": "img",
123
+ "src": "/content/products/24/00/35/24003529/jcr:content/fullImage.imgw.1280.1280.png",
124
+ "alt": ""
125
+ }
126
+ ],
127
+ "thumbnail": thumbnailImage,
128
+ ingredients: mapIngredients(eqVariant.properties.ingredients),
129
+ "benefits": eqVariant.properties.benefits,
130
+ "usage": eqVariant.properties.usage,
131
+ "resources": eqVariant.properties.resources,
132
+ "videos": "",
133
+ "movie": "",
134
+ "youtube": "",
135
+ "salesEventText": "",
136
+ "contentSection": [
137
+ {
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"
139
+ }
140
+ ],
141
+ "scanQualified": eqVariant.properties.scanQualifiedCount,
142
+ "availableQuantity": eqVariant.inventoryProperties.atpQty,
143
+ "maxQuantity": 999,
144
+ "points": "",
145
+ "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
146
+ "pv": eqVariant.priceFacets.PV,
147
+ "priceType": "WRTL",
148
+ "price": eqVariant.priceFacets["Regular Price"],
149
+ "priceMap": {
150
+ "WRTL": eqVariant.priceFacets["Regular Price"],
151
+ "WADW-WRTL": eqVariant.priceFacets["Regular Price"],
152
+ "WADR": 9999.01,
153
+ "RTL": eqVariant.priceFacets["Regular Price"],
154
+ "WWHL": eqVariant.priceFacets["Wholesale Price"],
155
+ "WADW": 9998.01,
156
+ "WHL": eqVariant.priceFacets["Wholesale Price"]
157
+ },
158
+ "cvMap": {
159
+ "WWHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
160
+ "WADW": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
161
+ "WHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : ''
162
+ },
163
+ "pvMap": {
164
+ "WWHL": eqVariant.priceFacets.PV,
165
+ "WADW": eqVariant.priceFacets.PV,
166
+ "WHL": eqVariant.priceFacets.PV
167
+ },
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
+ },
181
+ "division": eqVariant.properties.division,
182
+ "backOrderDate": null,
183
+ "locallyProduced": false,
184
+ "agelocme": null,
185
+ "count": "",
186
+ "flavor": "",
187
+ "size": eqVariant.properties.size,
188
+ "shade": "",
189
+ "status": this.switchStatusFromEquinox(eqVariant.properties.status),
190
+ "variantType": "Other",
191
+ "variantDropdownLabel": eqVariant.properties.variantLabel || "",
192
+ "variantDropdownPlaceholder": "Select Type",
193
+ "variantsLabel": eqVariant.properties.variantLabel || "",
194
+ "groupOffer": false,
195
+ "personalOffer": false,
196
+ "savedEventName": null,
197
+ "salesLabel": "",
198
+ "eventName": null,
199
+ "sizeWeight": '',
200
+ "nettoWeight": "",
201
+ "searchScore": 0,
202
+ "isExclusive": false,
203
+ "marketAttributes": {
204
+ "discount": true,
205
+ "redeem": true,
206
+ "earn": true
207
+ },
208
+ "restrictedMarkets": [],
209
+ "addOns": []
210
+ };
211
+ },
212
+
213
+ eqProductMapper: function (productDataResponse, skus) {
94
214
  let prod = [];
95
215
  let count = 0;
216
+ let variants = {};
96
217
 
97
218
  let prodArr = productDataResponse.map((data) => {
98
219
  let imageURL = data.sku[count].properties.imageURL;
99
220
  const regex = /\d+.\d+/
100
221
  let thumbnailImage = ''
101
-
222
+
102
223
  if (imageURL.includes('contentstack')) {
103
224
  thumbnailImage = imageURL + '?width=40'
104
225
  } else {
105
- thumbnailImage = imageURL.replace(regex,'40.40')
226
+ thumbnailImage = imageURL.replace(regex, '40.40')
227
+ }
228
+
229
+ if (data.sku && data.sku.length > 1) {
230
+ data.sku.map(variant => {
231
+ variants[variant.identifier] = this.eqProductVariantMapper(variant);
232
+ return variant;
233
+ });
106
234
  }
107
- const skuProperties = data.sku[count].properties;
108
235
 
109
236
  prod = {
110
237
  "sku": data.sku[count].identifier,
@@ -116,8 +243,8 @@ const ProductData = {
116
243
  "longDescr": data.properties.productDetailsDescription,
117
244
  "fullImage": imageURL,
118
245
  "imageAltText": data.properties.name,
119
- productCarouselImages: skuProperties.productImages
120
- ? JSON.parse(skuProperties.productImages).map(img => (
246
+ productCarouselImages: data.sku[count].properties.productImages
247
+ ? JSON.parse(data.sku[count].properties.productImages).map(img => (
121
248
  {
122
249
  contentType: /\.jpg/i.test(img.url) ? 'img' : 'video',
123
250
  src: img.url,
@@ -125,10 +252,10 @@ const ProductData = {
125
252
  }
126
253
  )) : [],
127
254
  "thumbnail": thumbnailImage,
128
- "ingredients": data.properties.ingredients,
129
- "benefits": data.properties.benefits,
130
- "usage": data.properties.usage,
131
- "resources": data.sku[count].properties.resources,
255
+ ingredients: mapIngredients(data.properties.ingredients),
256
+ benefits: mapBenefits(data.properties.benefits),
257
+ usage: mapUsage(data.properties.usage),
258
+ resources: mapResources(data.properties.resources),
132
259
  "videos": "",
133
260
  "movie": "",
134
261
  "youtube": "",
@@ -139,10 +266,10 @@ const ProductData = {
139
266
  }
140
267
  ],
141
268
  "scanQualified": data.properties.scanQualifiedCount,
142
- "availableQuantity": 999,
269
+ "availableQuantity": data.sku[count].inventoryProperties.atpQty,
143
270
  "maxQuantity": 999,
144
271
  "points": "",
145
- "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
272
+ "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
146
273
  "pv": data.sku[count].priceFacets.PV,
147
274
  "priceType": "WRTL",
148
275
  "price": data.sku[count].priceFacets["Regular Price"],
@@ -151,9 +278,9 @@ const ProductData = {
151
278
  "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
152
279
  "WADR": 9999.01,
153
280
  "RTL": data.sku[count].priceFacets["Regular Price"],
154
- "WWHL": 9998.01,
155
281
  "WADW": 9998.01,
156
- "WHL": 9998.01
282
+ "WHL": data.sku[count].priceFacets["Wholesale Price"],
283
+ "WWHL": data.sku[count].priceFacets["Wholesale Price"]
157
284
  },
158
285
  "cvMap": {
159
286
  "WWHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
@@ -190,9 +317,9 @@ const ProductData = {
190
317
  "shade": "",
191
318
  "status": this.switchStatusFromEquinox(data.sku[count].properties.productStatus),
192
319
  "variantType": "Other",
193
- "variantDropdownLabel": "Select Type",
320
+ "variantDropdownLabel": data.sku[count].properties.variantLabel || "",
194
321
  "variantDropdownPlaceholder": "Select Type",
195
- "variantsLabel": "Select Type",
322
+ "variantsLabel": data.sku[count].properties.variantLabel || "",
196
323
  "groupOffer": false,
197
324
  "personalOffer": false,
198
325
  "savedEventName": null,
@@ -200,8 +327,7 @@ const ProductData = {
200
327
  "eventName": null,
201
328
  "sizeWeight": '',
202
329
  "nettoWeight": "",
203
- "variants": {
204
- },
330
+ "variants": variants,
205
331
  "searchScore": 0,
206
332
  "isExclusive": data.sku[count].properties.isExclusive,
207
333
  "marketAttributes": {
@@ -210,14 +336,16 @@ const ProductData = {
210
336
  "earn": true
211
337
  },
212
338
  "restrictedMarkets": [],
213
- "addOns": []
339
+ "addOns": [],
340
+ "inventory": data.sku[count].inventory || "" //inventory label
341
+
214
342
  };
215
- let newProduct = new product(prod);
343
+ let newProduct = new Product(prod);
216
344
  return newProduct
217
345
  })
218
346
 
219
347
  let data = {
220
- products: prodArr,
348
+ products: this._sortProductsBySku(skus, prodArr),
221
349
  count: productDataResponse.length
222
350
  };
223
351
  return {
@@ -255,19 +383,105 @@ const ProductData = {
255
383
  },
256
384
 
257
385
  /**
258
- *
259
- * @param {*} custType
260
- *
386
+ *
387
+ * @param {*} custType
388
+ *
261
389
  */
262
390
  switchCustType: function (custType) {
263
391
  let newCustType = [];
264
- if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
392
+ if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
265
393
  newCustType.push(10)
266
394
  if (custType.includes('Retail Customer'))
267
395
  newCustType.push(20)
268
396
  if (custType.includes('Preferred Customer/Member'))
269
397
  newCustType.push(30)
270
398
  return newCustType.toString()
399
+ },
400
+
401
+ /**
402
+ * Sorts the product by sku
403
+ * @param {Array} skus - the skus arrangment which the sorting will base out of
404
+ * @param {Array} products - this products to be sorted
405
+ */
406
+
407
+ _sortProductsBySku: function (skus, products) {
408
+
409
+ if (!skus || !products || products.length === 1) {
410
+ return products
411
+ }
412
+
413
+ return products.sort(function (a, b) {
414
+ return skus.indexOf(a.sku) - skus.indexOf(b.sku);
415
+ });
416
+
417
+ }
418
+ }
419
+
420
+ function mapBenefits(benefits) {
421
+ if (!benefits) {
422
+ return {};
423
+ }
424
+
425
+ const list = JSON.parse(benefits)
426
+ .map(item => item.benefits.map(benefit => benefit).join(''))
427
+ .join('');
428
+
429
+ return {
430
+ benefitsHTML: list,
431
+ benefitsText: 'Benefits',
432
+ benefitItems: []
433
+ };
434
+ }
435
+
436
+ function mapIngredients(ingredients) {
437
+ if (!mapIngredients) {
438
+ return {};
439
+ }
440
+
441
+ // concatenating the name, description, keyIngredients, and otherIngredients
442
+ const list = JSON.parse(ingredients)
443
+ .map(i => [
444
+ i.keyIngredients
445
+ .map(k => `<img src="${k.image.url}" alt="${k.image.alt}" /> ${k.name} ${k.description}`)
446
+ .join(' '),
447
+ i.otherIngredients
448
+ ].join(' '))
449
+ .join(' ');
450
+
451
+ return {
452
+ ingredientsHTML: list,
453
+ ingredientsText: 'Ingredients',
454
+ ingredients: []
455
+ }
456
+ }
457
+
458
+ function mapResources(resources) {
459
+ if (!resources) {
460
+ return {};
461
+ }
462
+
463
+ const text = JSON.parse(resources)
464
+ .map(res => `<p><a href="${res.url}" target="_blank">${res.title}</a></p>`)
465
+ .join('');
466
+
467
+ return {
468
+ resourcesHTML: text,
469
+ resourcesText: 'Resources',
470
+ resourceLinks: []
471
+ }
472
+ }
473
+
474
+ function mapUsage(usage) {
475
+ if (!usage) {
476
+ return {};
477
+ }
478
+
479
+ const text = JSON.parse(usage).additionalText
480
+ .map(t => t).join('');
481
+
482
+ return {
483
+ usageHTML: text,
484
+ usageText: 'Usage'
271
485
  }
272
486
  }
273
487