@nuskin/ns-product-lib 2.4.0-cx24-2467.2.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,9 +1,106 @@
1
- # [2.4.0-cx24-2467.2.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.3.0...v2.4.0-cx24-2467.2.1) (2022-10-19)
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
2
 
3
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)
60
+
61
+
62
+ ### Fix
63
+
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)
65
+
4
66
  ### New
5
67
 
6
- * add support for product variant (#CX24-2467) ([3f5ad9e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/3f5ad9e6c0f00bf40470dbb940a234d55a9ef451)), closes [#CX24-2467](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2467)
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
+
90
+ ### Release
91
+
92
+ * Automated changes by GitLab pipeline [skip ci] ([8f75316](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/8f75316b692ddccda5b7bea830ee6dc625b942c7))
93
+ * Automated changes by GitLab pipeline [skip ci] ([36dca5b](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/36dca5b92285ae6d8ae96345256df92102efad8e))
94
+
95
+ ### Update
96
+
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)
7
104
 
8
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)
9
106
 
@@ -41,6 +138,39 @@
41
138
 
42
139
  * replace runConfig and marketConfig parameters of getProductData with locale and market (CX24-2382) ([b7b8ac7](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b7b8ac7fa946df0b3690f700d00f5acfb0073bcf))
43
140
 
141
+ ### Fix
142
+
143
+ * To make multiple products work (#CX24-2444) ([1cbe500](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/1cbe5000d2649157de3bdb6456d601fdeecbd3b6)), closes [#CX24-2444](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2444)
144
+ * To make multiple products work (#CX24-2444) ([b4c2218](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b4c221853dca33f2c0b06a06d6ead7fc50e9f0c6)), closes [#CX24-2444](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2444)
145
+
146
+ ### Release
147
+
148
+ * Automated changes by GitLab pipeline [skip ci] ([a974a24](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/a974a244a85ee42eca3540b88429d16edcbf57ce))
149
+ * Automated changes by GitLab pipeline [skip ci] ([aa21d8d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/aa21d8dcbed15a1c0798f882b4667bcc2bc071dc))
150
+
151
+ ### Update
152
+
153
+ * updating the product data map (#CX24-2103) ([ea914a4](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ea914a4079c2472adcd449fac09be85f22671493)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
154
+
155
+ # [2.0.0-cx24-21035.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-21035.1...v2.0.0-cx24-21035.2) (2022-09-22)
156
+
157
+
158
+ ### Fix
159
+
160
+ * To make multiple products work (#CX24-2444) ([1cbe500](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/1cbe5000d2649157de3bdb6456d601fdeecbd3b6)), closes [#CX24-2444](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2444)
161
+ * To make multiple products work (#CX24-2444) ([b4c2218](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b4c221853dca33f2c0b06a06d6ead7fc50e9f0c6)), closes [#CX24-2444](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2444)
162
+
163
+ ### Release
164
+
165
+ * Automated changes by GitLab pipeline [skip ci] ([aa21d8d](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/aa21d8dcbed15a1c0798f882b4667bcc2bc071dc))
166
+
167
+ ### Update
168
+
169
+ * updating the product data map (#CX24-2103) ([ea914a4](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ea914a4079c2472adcd449fac09be85f22671493)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
170
+
171
+ # [2.0.0-cx24-21035.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.0.0-cx24-21035.1...v2.0.0-cx24-21035.2) (2022-09-22)
172
+
173
+
44
174
  ### Fix
45
175
 
46
176
  * To make multiple products work (#CX24-2444) ([b4c2218](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/b4c221853dca33f2c0b06a06d6ead7fc50e9f0c6)), closes [#CX24-2444](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2444)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-product-lib",
3
- "version": "2.4.0-cx24-2467.2.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);
@@ -30,7 +30,6 @@ const ProductData = {
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 {
@@ -82,7 +81,7 @@ const ProductData = {
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,
@@ -96,7 +95,7 @@ const ProductData = {
96
95
  * @param {*} eqVariant
97
96
  * @returns Array<Product>
98
97
  */
99
- eqProductVariantMapper : function (eqVariant) {
98
+ eqProductVariantMapper: function (eqVariant) {
100
99
 
101
100
  let imageURL = eqVariant.properties.imageURL;
102
101
  const regex = /\d+.\d+/
@@ -105,7 +104,7 @@ const ProductData = {
105
104
  if (imageURL.includes('contentstack')) {
106
105
  thumbnailImage = imageURL + '?width=40'
107
106
  } else {
108
- thumbnailImage = imageURL.replace(regex,'40.40')
107
+ thumbnailImage = imageURL.replace(regex, '40.40')
109
108
  }
110
109
 
111
110
  return {
@@ -126,7 +125,7 @@ const ProductData = {
126
125
  }
127
126
  ],
128
127
  "thumbnail": thumbnailImage,
129
- "ingredients": eqVariant.properties.ingredients,
128
+ ingredients: mapIngredients(eqVariant.properties.ingredients),
130
129
  "benefits": eqVariant.properties.benefits,
131
130
  "usage": eqVariant.properties.usage,
132
131
  "resources": eqVariant.properties.resources,
@@ -140,11 +139,11 @@ const ProductData = {
140
139
  }
141
140
  ],
142
141
  "scanQualified": eqVariant.properties.scanQualifiedCount,
143
- "availableQuantity": 999,
142
+ "availableQuantity": eqVariant.inventoryProperties.atpQty,
144
143
  "maxQuantity": 999,
145
144
  "points": "",
146
- "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
147
- "pv":eqVariant.priceFacets.PV,
145
+ "cv": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
146
+ "pv": eqVariant.priceFacets.PV,
148
147
  "priceType": "WRTL",
149
148
  "price": eqVariant.priceFacets["Regular Price"],
150
149
  "priceMap": {
@@ -152,9 +151,9 @@ const ProductData = {
152
151
  "WADW-WRTL": eqVariant.priceFacets["Regular Price"],
153
152
  "WADR": 9999.01,
154
153
  "RTL": eqVariant.priceFacets["Regular Price"],
155
- "WWHL": 9998.01,
154
+ "WWHL": eqVariant.priceFacets["Wholesale Price"],
156
155
  "WADW": 9998.01,
157
- "WHL": 9998.01
156
+ "WHL": eqVariant.priceFacets["Wholesale Price"]
158
157
  },
159
158
  "cvMap": {
160
159
  "WWHL": (eqVariant.priceFacets.CV) ? eqVariant.priceFacets.CV : '',
@@ -189,9 +188,9 @@ const ProductData = {
189
188
  "shade": "",
190
189
  "status": this.switchStatusFromEquinox(eqVariant.properties.status),
191
190
  "variantType": "Other",
192
- "variantDropdownLabel": "Select Type",
191
+ "variantDropdownLabel": eqVariant.properties.variantLabel || "",
193
192
  "variantDropdownPlaceholder": "Select Type",
194
- "variantsLabel": "Select Type",
193
+ "variantsLabel": eqVariant.properties.variantLabel || "",
195
194
  "groupOffer": false,
196
195
  "personalOffer": false,
197
196
  "savedEventName": null,
@@ -211,10 +210,10 @@ const ProductData = {
211
210
  };
212
211
  },
213
212
 
214
- eqProductMapper: function (productDataResponse) {
213
+ eqProductMapper: function (productDataResponse, skus) {
215
214
  let prod = [];
216
215
  let count = 0;
217
- const variants = {};
216
+ let variants = {};
218
217
 
219
218
  let prodArr = productDataResponse.map((data) => {
220
219
  let imageURL = data.sku[count].properties.imageURL;
@@ -224,7 +223,7 @@ const ProductData = {
224
223
  if (imageURL.includes('contentstack')) {
225
224
  thumbnailImage = imageURL + '?width=40'
226
225
  } else {
227
- thumbnailImage = imageURL.replace(regex,'40.40')
226
+ thumbnailImage = imageURL.replace(regex, '40.40')
228
227
  }
229
228
 
230
229
  if (data.sku && data.sku.length > 1) {
@@ -244,32 +243,33 @@ const ProductData = {
244
243
  "longDescr": data.properties.productDetailsDescription,
245
244
  "fullImage": imageURL,
246
245
  "imageAltText": data.properties.name,
247
- "productCarouselImages": [
248
- {
249
- "contentType": "img",
250
- "src": "/content/products/24/00/35/24003529/jcr:content/fullImage.imgw.1280.1280.png",
251
- "alt": ""
252
- }
253
- ],
246
+ productCarouselImages: data.sku[count].properties.productImages
247
+ ? JSON.parse(data.sku[count].properties.productImages).map(img => (
248
+ {
249
+ contentType: /\.jpg/i.test(img.url) ? 'img' : 'video',
250
+ src: img.url,
251
+ alt: img.alt
252
+ }
253
+ )) : [],
254
254
  "thumbnail": thumbnailImage,
255
- "ingredients": data.properties.ingredients,
256
- "benefits": data.properties.benefits,
257
- "usage": data.properties.usage,
258
- "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),
259
259
  "videos": "",
260
260
  "movie": "",
261
261
  "youtube": "",
262
262
  "salesEventText": "",
263
263
  "contentSection": [
264
264
  {
265
- "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"
265
+ "sectionContent": "<div class=\"contentSections\"></div>\n"
266
266
  }
267
267
  ],
268
268
  "scanQualified": data.properties.scanQualifiedCount,
269
- "availableQuantity": 999,
269
+ "availableQuantity": data.sku[count].inventoryProperties.atpQty,
270
270
  "maxQuantity": 999,
271
271
  "points": "",
272
- "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
272
+ "cv": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
273
273
  "pv": data.sku[count].priceFacets.PV,
274
274
  "priceType": "WRTL",
275
275
  "price": data.sku[count].priceFacets["Regular Price"],
@@ -278,9 +278,9 @@ const ProductData = {
278
278
  "WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
279
279
  "WADR": 9999.01,
280
280
  "RTL": data.sku[count].priceFacets["Regular Price"],
281
- "WWHL": data.sku[count].priceFacets["Regular Price"],
282
281
  "WADW": 9998.01,
283
- "WHL": data.sku[count].priceFacets["Regular Price"]
282
+ "WHL": data.sku[count].priceFacets["Wholesale Price"],
283
+ "WWHL": data.sku[count].priceFacets["Wholesale Price"]
284
284
  },
285
285
  "cvMap": {
286
286
  "WWHL": (data.sku[count].priceFacets.CV) ? data.sku[count].priceFacets.CV : '',
@@ -317,9 +317,9 @@ const ProductData = {
317
317
  "shade": "",
318
318
  "status": this.switchStatusFromEquinox(data.sku[count].properties.productStatus),
319
319
  "variantType": "Other",
320
- "variantDropdownLabel": "Select Type",
320
+ "variantDropdownLabel": data.sku[count].properties.variantLabel || "",
321
321
  "variantDropdownPlaceholder": "Select Type",
322
- "variantsLabel": "Select Type",
322
+ "variantsLabel": data.sku[count].properties.variantLabel || "",
323
323
  "groupOffer": false,
324
324
  "personalOffer": false,
325
325
  "savedEventName": null,
@@ -336,14 +336,16 @@ const ProductData = {
336
336
  "earn": true
337
337
  },
338
338
  "restrictedMarkets": [],
339
- "addOns": []
339
+ "addOns": [],
340
+ "inventory": data.sku[count].inventory || "" //inventory label
341
+
340
342
  };
341
343
  let newProduct = new Product(prod);
342
344
  return newProduct
343
345
  })
344
346
 
345
347
  let data = {
346
- products: prodArr,
348
+ products: this._sortProductsBySku(skus, prodArr),
347
349
  count: productDataResponse.length
348
350
  };
349
351
  return {
@@ -394,6 +396,92 @@ const ProductData = {
394
396
  if (custType.includes('Preferred Customer/Member'))
395
397
  newCustType.push(30)
396
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'
397
485
  }
398
486
  }
399
487