@nuskin/ns-product-lib 1.5.0-cx24-2126.2 → 1.5.0-cx24-2103.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -9
- package/package.json +2 -2
- package/src/index.js +1 -3
- package/src/productData.js +211 -149
- package/src/eqProduct.js +0 -812
package/CHANGELOG.md
CHANGED
@@ -1,24 +1,32 @@
|
|
1
|
-
# [1.5.0-cx24-
|
1
|
+
# [1.5.0-cx24-2103.3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v1.5.0-cx24-2103.2...v1.5.0-cx24-2103.3) (2022-09-08)
|
2
2
|
|
3
3
|
|
4
|
-
###
|
4
|
+
### Update
|
5
5
|
|
6
|
-
*
|
7
|
-
* update condition for dynamic kong URL (#CX24-2126) ([e0149a6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e0149a6fee3e9405709efbb2669abffd01fc8a5b)), closes [#CX24-2126](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2126)
|
6
|
+
* updating the product data map (#CX24-2103) ([680a718](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/680a7188c3ba1a9073f513277f14c1abb3356184)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
|
8
7
|
|
9
|
-
# [1.5.0-cx24-
|
8
|
+
# [1.5.0-cx24-2103.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v1.5.0-cx24-2103.1...v1.5.0-cx24-2103.2) (2022-09-07)
|
10
9
|
|
11
10
|
|
12
|
-
###
|
11
|
+
### Update
|
13
12
|
|
14
|
-
*
|
13
|
+
* updating the product data map (#CX24-2103) ([1d30f74](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/1d30f74bcca16de1440013c2a00048cace61bfc9)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
|
15
14
|
|
16
|
-
# [1.5.0-
|
15
|
+
# [1.5.0-cx24-2103.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v1.4.5...v1.5.0-cx24-2103.1) (2022-09-06)
|
17
16
|
|
18
17
|
|
19
18
|
### New
|
20
19
|
|
21
|
-
*
|
20
|
+
* get Product data from equinox (#CX24) ([9e4a93f](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9e4a93fd0cc24069a9f0fa81f309e606b2123523)), closes [#CX24](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24)
|
21
|
+
* get Product data from equinox (#CX24) ([2679c94](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/2679c941d1bf59eb0ad506f0bf83e9c7f1a3d10e)), closes [#CX24](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24)
|
22
|
+
* Get Product Data from Equinox (CX24-1810, CX24-2121) ([50f0bcc](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/50f0bcc7131fae0302abd9932c8d05bc1879ae11))
|
23
|
+
|
24
|
+
### Update
|
25
|
+
|
26
|
+
* updating the product data map (#CX24-2103) ([235b97b](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/235b97b58c3de6684909ce353824511e3993365c)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
|
27
|
+
* updating the product data map (#CX24-2103) ([6c072e8](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/6c072e8a56a7867fbdcac6705c3c0c3b559d6548)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
|
28
|
+
* updating the product data map (#CX24-2103) ([7a15ecb](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/7a15ecbe21e40982ff437540817c89e6edb49dde)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
|
29
|
+
* updating the product data map (#CX24-2103) ([9911760](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/9911760cd005cc91f5b5af323da80ab107e6f1ad)), closes [#CX24-2103](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/issues/CX24-2103)
|
22
30
|
|
23
31
|
## [1.4.5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v1.4.4...v1.4.5) (2022-07-28)
|
24
32
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nuskin/ns-product-lib",
|
3
|
-
"version": "1.5.0-cx24-
|
3
|
+
"version": "1.5.0-cx24-2103.3",
|
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": {
|
@@ -30,7 +30,7 @@
|
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
32
|
"@nuskin/ns-common-lib": "1.3.0",
|
33
|
-
"@nuskin/ns-util": "3.104.0
|
33
|
+
"@nuskin/ns-util": "3.104.0",
|
34
34
|
"axios": "0.27.2",
|
35
35
|
"qs": "6.11.0"
|
36
36
|
},
|
package/src/index.js
CHANGED
@@ -13,7 +13,6 @@ const ProductStatus = require("./productStatus.js");
|
|
13
13
|
const ProductStatusMapper = require("./productStatusMapper.js");
|
14
14
|
const ProductUtils = require("./productUtils.js");
|
15
15
|
const ProductData = require("./productData.js");
|
16
|
-
const EqProduct = require("./eqProduct.js");
|
17
16
|
|
18
17
|
module.exports = {
|
19
18
|
Agelocme,
|
@@ -23,6 +22,5 @@ module.exports = {
|
|
23
22
|
ProductStatus,
|
24
23
|
ProductStatusMapper,
|
25
24
|
ProductUtils,
|
26
|
-
ProductData
|
27
|
-
EqProduct
|
25
|
+
ProductData
|
28
26
|
};
|
package/src/productData.js
CHANGED
@@ -1,47 +1,53 @@
|
|
1
1
|
"use strict";
|
2
2
|
const axios = require("axios");
|
3
3
|
const product = require("./product")
|
4
|
-
|
4
|
+
/** @type {*} */
|
5
5
|
const ProductData = {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
method: 'get',
|
18
|
-
url: `${kongBaseUrl}/orchestrationservices/storefront/catalogs/search/`,
|
19
|
-
params: {
|
20
|
-
locale: locale,
|
21
|
-
storeId: '406',
|
22
|
-
filter: filter
|
23
|
-
},
|
24
|
-
headers: this.getProductDataRequestHeaders(marketConfig),
|
25
|
-
responseType: "json"
|
26
|
-
});
|
27
|
-
productResponse = this.eqProductMapper(productDataResponse.data.product)
|
28
|
-
|
29
|
-
} else {
|
30
|
-
let lambdaUrl = `${marketConfig.awsUrl}/productData/v1`;
|
31
|
-
const payload = {
|
32
|
-
locale: locale,
|
33
|
-
skus: skus
|
34
|
-
};
|
35
|
-
productResponse = await axios.request({
|
36
|
-
method: "post",
|
37
|
-
url: lambdaUrl,
|
38
|
-
data: payload,
|
39
|
-
headers: this.getProductDataRequestHeaders(marketConfig),
|
40
|
-
responseType: "json"
|
41
|
-
});
|
6
|
+
/**
|
7
|
+
* @param {*} skus
|
8
|
+
* @param {*} runConfig
|
9
|
+
* @param {*} marketConfig
|
10
|
+
* @param {{ isEnabled: boolean, storeID: string }} equinoxOptions
|
11
|
+
*/
|
12
|
+
getProductData: async function (skus, runConfig, marketConfig, equinoxOptions) {
|
13
|
+
const locale = `${runConfig.language}_${runConfig.country}`;
|
14
|
+
console.log(equinoxOptions)
|
15
|
+
if (equinoxOptions !== undefined && equinoxOptions.isEnabled === true) {
|
16
|
+
return await this.getProductFromEquinox(skus, locale, marketConfig, equinoxOptions.storeID);
|
42
17
|
}
|
43
18
|
|
44
|
-
return
|
19
|
+
return await this.getProductFromLegacy(skus, locale, marketConfig);
|
20
|
+
},
|
21
|
+
|
22
|
+
getProductFromEquinox: async function(skus, locale, marketConfig, storeID) {
|
23
|
+
const filter = `{"filters": [{"field": "index_key_skuId","operation": "IN","value": "${skus.toString()}"}]}`;
|
24
|
+
axios.defaults.withCredentials = true;
|
25
|
+
const productDataResponse = await axios.request({
|
26
|
+
method: 'get',
|
27
|
+
url: `https://storefront.api.wde.nuskin.io/orchestrationservices/storefront/catalogs/search/`,
|
28
|
+
params: {
|
29
|
+
locale,
|
30
|
+
storeId: storeID,
|
31
|
+
filter
|
32
|
+
},
|
33
|
+
headers: this.getProductDataRequestHeaders(marketConfig),
|
34
|
+
responseType: "json"
|
35
|
+
});
|
36
|
+
|
37
|
+
return this.eqProductMapper(productDataResponse.data.product);
|
38
|
+
},
|
39
|
+
|
40
|
+
getProductFromLegacy: async function(skus, locale, marketConfig) {
|
41
|
+
const lambdaUrl = `${marketConfig.awsUrl}/productData/v1`;
|
42
|
+
const payload = { locale, skus };
|
43
|
+
|
44
|
+
return await axios.request({
|
45
|
+
method: "post",
|
46
|
+
url: lambdaUrl,
|
47
|
+
data: payload,
|
48
|
+
headers: this.getProductDataRequestHeaders(marketConfig),
|
49
|
+
responseType: "json"
|
50
|
+
});
|
45
51
|
},
|
46
52
|
|
47
53
|
/* eqProductMapper: function(productDataResponse) {
|
@@ -50,120 +56,14 @@ const ProductData = {
|
|
50
56
|
|
51
57
|
eqProductMapper: function (productDataResponse) {
|
52
58
|
let prodArr = [];
|
53
|
-
|
59
|
+
|
54
60
|
let count = 0;
|
55
61
|
productDataResponse.forEach((data, index) => {
|
56
|
-
|
57
|
-
|
58
|
-
prod = {
|
59
|
-
"sku": data.sku[0].identifier,
|
60
|
-
"globalProductID": data.identifier,
|
61
|
-
"title": data.properties.name,
|
62
|
-
"country": data.sku[0].properties.market,
|
63
|
-
"language": "en",
|
64
|
-
"shortDescr": data.properties.description,
|
65
|
-
"longDescr": data.properties.productDetailsDescription,
|
66
|
-
"fullImage": data.properties.imageURL,
|
67
|
-
"imageAltText": data.properties.name,
|
68
|
-
"productCarouselImages": [
|
69
|
-
{
|
70
|
-
"contentType": "img",
|
71
|
-
"src": "/content/products/24/00/35/24003529/jcr:content/fullImage.imgw.1280.1280.png",
|
72
|
-
"alt": ""
|
73
|
-
}
|
74
|
-
],
|
75
|
-
"thumbnail": "/content/products/24/11/08/24110845/jcr:content/fullImage.img.160.160.png/1490766406581-cache.png",
|
76
|
-
"ingredients": "",
|
77
|
-
"benefits": "",
|
78
|
-
"usage": "",
|
79
|
-
"resources": "",
|
80
|
-
"videos": "",
|
81
|
-
"movie": "",
|
82
|
-
"youtube": "",
|
83
|
-
"salesEventText": "",
|
84
|
-
"contentSection": [
|
85
|
-
{
|
86
|
-
"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%\"> </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> </p>\r\n\n</div>\n\n</div>\n\n</div>\n</div>\n</div>\n</div>\n"
|
87
|
-
}
|
88
|
-
],
|
89
|
-
"scanQualified": data.properties.scanQualifiedCount,
|
90
|
-
"availableQuantity": 999,
|
91
|
-
"maxQuantity": 999,
|
92
|
-
"points": "",
|
93
|
-
"cv": 99.1,
|
94
|
-
"pv": 99.01,
|
95
|
-
"priceType": "WRTL",
|
96
|
-
"price": 9999.11,
|
97
|
-
"priceMap": {
|
98
|
-
"WRTL": 9999.11,
|
99
|
-
"WADW-WRTL": 9999.11,
|
100
|
-
"WADR": 9999.01,
|
101
|
-
"RTL": 9999.11,
|
102
|
-
"WWHL": 9998.01,
|
103
|
-
"WADW": 9998.01,
|
104
|
-
"WHL": 9998.01
|
105
|
-
},
|
106
|
-
"cvMap": {
|
107
|
-
"WWHL": 8888,
|
108
|
-
"WADW": 8888,
|
109
|
-
"WHL": 8888
|
110
|
-
},
|
111
|
-
"pvMap": {
|
112
|
-
"WWHL": 99,
|
113
|
-
"WADW": 98,
|
114
|
-
"WHL": 90
|
115
|
-
},
|
116
|
-
"orderTypes": {
|
117
|
-
"adr": true,
|
118
|
-
"order": true,
|
119
|
-
"zpfc": false,
|
120
|
-
"zadp": true,
|
121
|
-
"ars": true,
|
122
|
-
"kiosk": true,
|
123
|
-
"mobile": true,
|
124
|
-
"preferred customer": true,
|
125
|
-
"retail": true,
|
126
|
-
"web": true,
|
127
|
-
"web display": true
|
128
|
-
},
|
129
|
-
"childSkus": [],
|
130
|
-
"custTypes": [
|
131
|
-
"10"
|
132
|
-
],
|
133
|
-
"division": "",
|
134
|
-
"backOrderDate": null,
|
135
|
-
"locallyProduced": false,
|
136
|
-
"agelocme": null,
|
137
|
-
"count": "",
|
138
|
-
"flavor": "",
|
139
|
-
"size": "",
|
140
|
-
"shade": "",
|
141
|
-
"status": "RELEASED_FOR_SALE",
|
142
|
-
"variantType": "",
|
143
|
-
"variantDropdownLabel": "",
|
144
|
-
"variantDropdownPlaceholder": "",
|
145
|
-
"variantsLabel": "",
|
146
|
-
"groupOffer": false,
|
147
|
-
"personalOffer": false,
|
148
|
-
"savedEventName": null,
|
149
|
-
"salesLabel": "",
|
150
|
-
"eventName": null,
|
151
|
-
"sizeWeight": "120 capsules",
|
152
|
-
"nettoWeight": "",
|
153
|
-
"variants": {
|
154
|
-
},
|
155
|
-
"searchScore": 0,
|
156
|
-
"isExclusive": false,
|
157
|
-
"marketAttributes": {
|
158
|
-
"discount": true,
|
159
|
-
"redeem": true,
|
160
|
-
"earn": true
|
161
|
-
},
|
162
|
-
"restrictedMarkets": [],
|
163
|
-
"addOns": []
|
164
|
-
};
|
62
|
+
|
63
|
+
let prod = this.setProductDatatoJson(data, index);
|
165
64
|
let newProduct = new product(prod);
|
166
65
|
prodArr[index] = newProduct;
|
66
|
+
count++;
|
167
67
|
|
168
68
|
});
|
169
69
|
|
@@ -181,13 +81,175 @@ const ProductData = {
|
|
181
81
|
|
182
82
|
},
|
183
83
|
|
84
|
+
setProductDatatoJson: function(data, count) {
|
85
|
+
let prod = [];
|
86
|
+
let imageURL = data.sku[count].properties.imageURL;
|
87
|
+
const regex = /\d+.\d+/
|
88
|
+
let thumbnailImage = ''
|
89
|
+
|
90
|
+
if (imageURL.includes('contentstack')) {
|
91
|
+
thumbnailImage = imageURL + '?width=40'
|
92
|
+
} else {
|
93
|
+
thumbnailImage = imageURL.replace(regex,'40.40')
|
94
|
+
}
|
95
|
+
|
96
|
+
prod = {
|
97
|
+
"sku": data.sku[count].identifier,
|
98
|
+
"globalProductID": data.identifier,
|
99
|
+
"title": data.properties.name,
|
100
|
+
"country": data.sku[count].properties.market,
|
101
|
+
"language": "en",
|
102
|
+
"shortDescr": data.properties.description,
|
103
|
+
"longDescr": data.properties.productDetailsDescription,
|
104
|
+
"fullImage": imageURL,
|
105
|
+
"imageAltText": data.properties.name,
|
106
|
+
"productCarouselImages": [
|
107
|
+
{
|
108
|
+
"contentType": "img",
|
109
|
+
"src": "/content/products/24/00/35/24003529/jcr:content/fullImage.imgw.1280.1280.png",
|
110
|
+
"alt": ""
|
111
|
+
}
|
112
|
+
],
|
113
|
+
"thumbnail": thumbnailImage,
|
114
|
+
"ingredients": data.properties.ingredients,
|
115
|
+
"benefits": data.properties.benefits,
|
116
|
+
"usage": data.properties.usage,
|
117
|
+
"resources": data.sku[count].properties.resources,
|
118
|
+
"videos": "",
|
119
|
+
"movie": "",
|
120
|
+
"youtube": "",
|
121
|
+
"salesEventText": "",
|
122
|
+
"contentSection": [
|
123
|
+
{
|
124
|
+
"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%\"> </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> </p>\r\n\n</div>\n\n</div>\n\n</div>\n</div>\n</div>\n</div>\n"
|
125
|
+
}
|
126
|
+
],
|
127
|
+
"scanQualified": data.properties.scanQualifiedCount,
|
128
|
+
"availableQuantity": 999,
|
129
|
+
"maxQuantity": 999,
|
130
|
+
"points": "",
|
131
|
+
"cv": data.sku[count].priceFacets.CV,
|
132
|
+
"pv": data.sku[count].priceFacets.PV,
|
133
|
+
"priceType": "WRTL",
|
134
|
+
"price": data.sku[count].priceFacets["Regular Price"],
|
135
|
+
"priceMap": {
|
136
|
+
"WRTL": data.sku[count].priceFacets["Regular Price"],
|
137
|
+
"WADW-WRTL": data.sku[count].priceFacets["Regular Price"],
|
138
|
+
"WADR": 9999.01,
|
139
|
+
"RTL": data.sku[count].priceFacets["Regular Price"],
|
140
|
+
"WWHL": 9998.01,
|
141
|
+
"WADW": 9998.01,
|
142
|
+
"WHL": 9998.01
|
143
|
+
},
|
144
|
+
"cvMap": {
|
145
|
+
"WWHL": data.sku[count].priceFacets.CV,
|
146
|
+
"WADW": data.sku[count].priceFacets.CV,
|
147
|
+
"WHL": data.sku[count].priceFacets.CV
|
148
|
+
},
|
149
|
+
"pvMap": {
|
150
|
+
"WWHL": data.sku[count].priceFacets.PV,
|
151
|
+
"WADW": data.sku[count].priceFacets.PV,
|
152
|
+
"WHL": data.sku[count].priceFacets.PV
|
153
|
+
},
|
154
|
+
"orderTypes": {
|
155
|
+
"adr": true,
|
156
|
+
"order": true,
|
157
|
+
"zpfc": false,
|
158
|
+
"zadp": true,
|
159
|
+
"ars": true,
|
160
|
+
"kiosk": true,
|
161
|
+
"mobile": true,
|
162
|
+
"preferred customer": true,
|
163
|
+
"retail": true,
|
164
|
+
"web": true,
|
165
|
+
"web display": true
|
166
|
+
},
|
167
|
+
"childSkus": [],
|
168
|
+
"custTypes": this.switchCustType(data.properties.customerTypes),
|
169
|
+
"division": data.properties.division,
|
170
|
+
"backOrderDate": null,
|
171
|
+
"locallyProduced": false,
|
172
|
+
"agelocme": null,
|
173
|
+
"count": "",
|
174
|
+
"flavor": "",
|
175
|
+
"size": data.sku[count].properties.size,
|
176
|
+
"shade": "",
|
177
|
+
"status": this.switchStatusFromEquinox(data.sku[count].properties.productStatus),
|
178
|
+
"variantType": "Other",
|
179
|
+
"variantDropdownLabel": "Select Type",
|
180
|
+
"variantDropdownPlaceholder": "Select Type",
|
181
|
+
"variantsLabel": "Select Type",
|
182
|
+
"groupOffer": false,
|
183
|
+
"personalOffer": false,
|
184
|
+
"savedEventName": null,
|
185
|
+
"salesLabel": "",
|
186
|
+
"eventName": null,
|
187
|
+
"sizeWeight": '',
|
188
|
+
"nettoWeight": "",
|
189
|
+
"variants": {
|
190
|
+
},
|
191
|
+
"searchScore": 0,
|
192
|
+
"isExclusive": false,
|
193
|
+
"marketAttributes": {
|
194
|
+
"discount": true,
|
195
|
+
"redeem": true,
|
196
|
+
"earn": true
|
197
|
+
},
|
198
|
+
"restrictedMarkets": [],
|
199
|
+
"addOns": []
|
200
|
+
};
|
201
|
+
return prod;
|
202
|
+
},
|
203
|
+
|
184
204
|
getProductDataRequestHeaders: function (marketConfig) {
|
185
205
|
return {
|
186
206
|
"Content-Type": "application/json",
|
187
207
|
client_id: marketConfig.checkout.clientId,
|
188
|
-
client_secret: marketConfig.checkout.clientSecret
|
208
|
+
client_secret: marketConfig.checkout.clientSecret
|
189
209
|
};
|
210
|
+
},
|
211
|
+
|
212
|
+
switchStatusFromEquinox: function (status) {
|
213
|
+
let newStatus = '';
|
214
|
+
switch (status) {
|
215
|
+
case 'Sellable':
|
216
|
+
newStatus = 'RELEASED_FOR_SALE';
|
217
|
+
break;
|
218
|
+
case 'Preview product':
|
219
|
+
newStatus = 'NOT_RELEASED_FOR_SALE';
|
220
|
+
break;
|
221
|
+
case 'Discontinued':
|
222
|
+
newStatus = 'DISCONTINUED';
|
223
|
+
break;
|
224
|
+
case 'Stopped':
|
225
|
+
newStatus = 'DISCONTINUED';
|
226
|
+
break;
|
227
|
+
case 'Replacement':
|
228
|
+
newStatus = 'NOT_RELEASED_FOR_SALE';
|
229
|
+
break;
|
230
|
+
default:
|
231
|
+
newStatus = 'NOT_RELEASED_FOR_SALE'
|
232
|
+
break;
|
233
|
+
}
|
234
|
+
return newStatus;
|
235
|
+
},
|
236
|
+
|
237
|
+
/**
|
238
|
+
*
|
239
|
+
* @param {*} custType
|
240
|
+
*
|
241
|
+
*/
|
242
|
+
switchCustType: function (custType) {
|
243
|
+
let newCustType = [];
|
244
|
+
if (custType.includes('Brand Affiliate - Business Entity') || custType.includes('Brand Affiliate - Individual'))
|
245
|
+
newCustType.push(10)
|
246
|
+
if (custType.includes('Retail Customer'))
|
247
|
+
newCustType.push(20)
|
248
|
+
if (custType.includes('Preferred Customer/Member'))
|
249
|
+
newCustType.push(30)
|
250
|
+
return newCustType.toString()
|
190
251
|
}
|
252
|
+
|
191
253
|
}
|
192
254
|
|
193
255
|
module.exports = ProductData;
|
package/src/eqProduct.js
DELETED
@@ -1,812 +0,0 @@
|
|
1
|
-
/* eslint-disable no-invalid-this */
|
2
|
-
"use strict";
|
3
|
-
|
4
|
-
const { isTrue } = require("@nuskin/ns-common-lib");
|
5
|
-
|
6
|
-
const ProductUtils = require("./productUtils.js");
|
7
|
-
|
8
|
-
const Agelocme = require("./agelocme.js");
|
9
|
-
const PriceType = require("./priceType.js");
|
10
|
-
const ProductStatus = require("./productStatus.js");
|
11
|
-
|
12
|
-
const eqProduct = function(productData) {
|
13
|
-
this.priceMap = {};
|
14
|
-
this.pvMap = {};
|
15
|
-
this.cvMap = {};
|
16
|
-
this.orderTypes = {};
|
17
|
-
this.childSkus = [];
|
18
|
-
this.custTypes = [];
|
19
|
-
this.addOns = [];
|
20
|
-
this.restrictedMarkets = [];
|
21
|
-
this.productCarouselImages = [];
|
22
|
-
this.locallyProduced = false;
|
23
|
-
|
24
|
-
//class variables to be used instead of getters/setters
|
25
|
-
this.globalProductID = "";
|
26
|
-
this.sku = "";
|
27
|
-
this.title = "";
|
28
|
-
this.country = "";
|
29
|
-
this.lang = "";
|
30
|
-
this.shortDescr = "";
|
31
|
-
this.longDescr = "";
|
32
|
-
this.sizeWeight = "";
|
33
|
-
this.nettoWeight = "";
|
34
|
-
this.productLabels = {};
|
35
|
-
this.count = "";
|
36
|
-
this.flavor = "";
|
37
|
-
this.shade = "";
|
38
|
-
this.size = "";
|
39
|
-
this.variantType = "";
|
40
|
-
this.variantDropdownLabel = "";
|
41
|
-
this.variantDropdownPlaceholder = "";
|
42
|
-
this.variantsLabel = "";
|
43
|
-
this.ingredients = "";
|
44
|
-
this.benefits = "";
|
45
|
-
this.usage = "";
|
46
|
-
this.resources = "";
|
47
|
-
this.contentSection = "";
|
48
|
-
this.videos = "";
|
49
|
-
this.personalOffer = false;
|
50
|
-
this.groupOffer = false;
|
51
|
-
this.scanQualified;
|
52
|
-
this.status = ProductStatus.ReleasedForSale;
|
53
|
-
this.availableQuantity = 0; // total available quantity
|
54
|
-
this.maxQuantity = 999; // max quantity allowed for purchase
|
55
|
-
this.priceType = null;
|
56
|
-
this.division = "";
|
57
|
-
this.backOrderDate = null;
|
58
|
-
this.baseSku = "";
|
59
|
-
this.variants = {};
|
60
|
-
this.eventName = null; // set if pricing is based off of an event
|
61
|
-
// Used to remember an event that was used for pricing in case ADR checkbox was clicked where
|
62
|
-
// event pricing is not available. If the event was active when the product was added then
|
63
|
-
// then the event can be used for the duration of the cart.
|
64
|
-
this.savedEventName = null;
|
65
|
-
this.salesLabel = "";
|
66
|
-
this.searchScore = 0;
|
67
|
-
this.isExclusive = false;
|
68
|
-
this.movie = "";
|
69
|
-
this.youtube = "";
|
70
|
-
this.marketAttributes = {};
|
71
|
-
this.salesEventText = "";
|
72
|
-
|
73
|
-
// agelocme stuff
|
74
|
-
this.agelocme = null; // object containing agelocme information (like code, label, name)
|
75
|
-
|
76
|
-
this.setMarketAttributes = function(productStatus) {
|
77
|
-
if (productStatus.marketAttributes) {
|
78
|
-
this.marketAttributes = productStatus.marketAttributes;
|
79
|
-
}
|
80
|
-
};
|
81
|
-
|
82
|
-
this.getAgelocmeKeyPart = function() {
|
83
|
-
let keyPart = null;
|
84
|
-
if (this.agelocme) {
|
85
|
-
keyPart =
|
86
|
-
this.agelocme.code +
|
87
|
-
"-" +
|
88
|
-
this.agelocme.label +
|
89
|
-
"-" +
|
90
|
-
this.agelocme.name;
|
91
|
-
}
|
92
|
-
|
93
|
-
return keyPart;
|
94
|
-
};
|
95
|
-
|
96
|
-
this.getHighlightedSku = function() {
|
97
|
-
let rv = this.sku;
|
98
|
-
if (this.highlightedSku) rv = this.highlightedSku;
|
99
|
-
return rv;
|
100
|
-
};
|
101
|
-
|
102
|
-
this.getProductSearchTitle = function() {
|
103
|
-
if (this.agelocme && this.agelocme.label) {
|
104
|
-
return this.agelocme.label;
|
105
|
-
}
|
106
|
-
return this.title;
|
107
|
-
};
|
108
|
-
|
109
|
-
this.getProductSearchSku = function() {
|
110
|
-
if (this.agelocme && this.agelocme.code) {
|
111
|
-
return this.agelocme.code;
|
112
|
-
}
|
113
|
-
return this.getHighlightedSku();
|
114
|
-
};
|
115
|
-
|
116
|
-
this.getDescription = function() {
|
117
|
-
let description = this.longDescr;
|
118
|
-
if (!description || description.length === 0) {
|
119
|
-
return this.shortDescr;
|
120
|
-
}
|
121
|
-
return description;
|
122
|
-
};
|
123
|
-
|
124
|
-
this.setFullImage = function(fullImage) {
|
125
|
-
if (fullImage) {
|
126
|
-
this.fullImage = fullImage.replace("http:", "https:");
|
127
|
-
} else {
|
128
|
-
this.fullImage = "";
|
129
|
-
}
|
130
|
-
};
|
131
|
-
|
132
|
-
this.getFullImage = function() {
|
133
|
-
return this.fullImage ? this.fullImage.replace("http:", "https:") : "";
|
134
|
-
};
|
135
|
-
|
136
|
-
this.setProductCarouselImages = function(productCarouselImages) {
|
137
|
-
this.productCarouselImages = productCarouselImages;
|
138
|
-
};
|
139
|
-
|
140
|
-
this.getProductCarouselImages = function() {
|
141
|
-
return this.productCarouselImages;
|
142
|
-
};
|
143
|
-
|
144
|
-
this.setImageAltText = function(altText) {
|
145
|
-
if (altText) {
|
146
|
-
this.imageAltText = altText;
|
147
|
-
} else {
|
148
|
-
this.imageAltText = this.title;
|
149
|
-
}
|
150
|
-
};
|
151
|
-
|
152
|
-
this.getImageAltText = function() {
|
153
|
-
return this.imageAltText || this.title;
|
154
|
-
};
|
155
|
-
|
156
|
-
this.setThumbnail = function(thumbnail) {
|
157
|
-
if (thumbnail) {
|
158
|
-
this.thumbnail = thumbnail.replace("http:", "https:");
|
159
|
-
} else {
|
160
|
-
this.thumbnail = "";
|
161
|
-
}
|
162
|
-
};
|
163
|
-
|
164
|
-
this.setThumbnailFromSku = function(sku) {
|
165
|
-
// WARNING: Base URL will need to be handled in the client (call setBaseUrl)
|
166
|
-
// eslint-disable-next-line max-len
|
167
|
-
// this.thumbnail = `${RunConfigService.getBaseUrl()}/content/products/${ProductUtils.getTokenizedSku(sku)}/jcr:content/fullImage.img.100.100.png`;
|
168
|
-
|
169
|
-
this.thumbnail = `/content/products/${ProductUtils.getTokenizedSku(
|
170
|
-
sku
|
171
|
-
)}/jcr:content/fullImage.img.100.100.png`;
|
172
|
-
};
|
173
|
-
|
174
|
-
this.getThumbnail = function() {
|
175
|
-
return this.thumbnail ? this.thumbnail.replace("http:", "https:") : "";
|
176
|
-
};
|
177
|
-
|
178
|
-
this.hasAvailableQuantity = function(qty = 1) {
|
179
|
-
return Math.min(this.maxQuantity, this.availableQuantity) >= qty;
|
180
|
-
};
|
181
|
-
|
182
|
-
this.setPoints = function(points) {
|
183
|
-
this.points = ensureFloatVal(points) || "";
|
184
|
-
};
|
185
|
-
|
186
|
-
this.getPointsFixed = function() {
|
187
|
-
return parseFloat(this.points).toFixed(2);
|
188
|
-
};
|
189
|
-
|
190
|
-
this.setCv = function(cv) {
|
191
|
-
this.cv = ensureFloatVal(cv) || "";
|
192
|
-
};
|
193
|
-
|
194
|
-
this.getCvFixed = function() {
|
195
|
-
return parseFloat(this.cv).toFixed(2);
|
196
|
-
};
|
197
|
-
|
198
|
-
this.setPv = function(pv) {
|
199
|
-
this.pv = ensureFloatVal(pv) || "";
|
200
|
-
};
|
201
|
-
|
202
|
-
this.getPvFixed = function() {
|
203
|
-
return parseFloat(this.pv || 0).toFixed(2);
|
204
|
-
};
|
205
|
-
|
206
|
-
this.setPrice = function(price) {
|
207
|
-
this.price = ensureFloatVal(price, true);
|
208
|
-
};
|
209
|
-
|
210
|
-
this.setFormattedPrice = function(formattedPrice) {
|
211
|
-
this.formattedPrice = formattedPrice;
|
212
|
-
};
|
213
|
-
|
214
|
-
/**
|
215
|
-
* Use to save the eventName if one exists. Added originally for when a product is
|
216
|
-
* added to the cart the event pricing needs to be remembered if toggling between
|
217
|
-
* pricetypes with event pricing and pricetype without event pricing
|
218
|
-
*/
|
219
|
-
this.lockEventName = function() {
|
220
|
-
if (!this.savedEventName && this.eventName) {
|
221
|
-
this.savedEventName = this.eventName;
|
222
|
-
}
|
223
|
-
};
|
224
|
-
|
225
|
-
this.setPriceAndPvFromType = function(_priceType, _activeEvents = null) {
|
226
|
-
// WARNING: priceType needs to be handled client-side
|
227
|
-
// const priceType = ConfigService.getMarketConfig().showWholeSalePricing && !AccountManager.isLoggedIn()
|
228
|
-
// ? PriceType.WWHL
|
229
|
-
// : (_priceType ? _priceType : this.priceType),
|
230
|
-
const priceType = _priceType ? _priceType : this.priceType;
|
231
|
-
const eventPricing = getEventPricing(this, priceType, _activeEvents);
|
232
|
-
|
233
|
-
let changed = false;
|
234
|
-
if (
|
235
|
-
!this.price ||
|
236
|
-
priceType !== this.priceType ||
|
237
|
-
this.eventName !== eventPricing.eventName
|
238
|
-
) {
|
239
|
-
this.setPrice(eventPricing.price || this.getPricing(priceType));
|
240
|
-
this.setCv(eventPricing.cv || this.getCvWithType(priceType));
|
241
|
-
this.setPv(eventPricing.pv || this.getPvWithType(priceType));
|
242
|
-
this.priceType = priceType;
|
243
|
-
this.eventName = eventPricing.eventName;
|
244
|
-
changed = true;
|
245
|
-
}
|
246
|
-
|
247
|
-
this.variantSkus().forEach((variantSku) => {
|
248
|
-
if (
|
249
|
-
this.variants[variantSku].setPriceAndPvFromType(
|
250
|
-
priceType,
|
251
|
-
_activeEvents
|
252
|
-
)
|
253
|
-
) {
|
254
|
-
changed = true;
|
255
|
-
}
|
256
|
-
}, this);
|
257
|
-
|
258
|
-
return changed;
|
259
|
-
};
|
260
|
-
|
261
|
-
this.getPrice = function() {
|
262
|
-
return this.price ? this.price : 0;
|
263
|
-
};
|
264
|
-
|
265
|
-
this.getPriceFixed = function() {
|
266
|
-
if (typeof this.price === "number") {
|
267
|
-
return parseFloat(this.price.toFixed(2));
|
268
|
-
} else {
|
269
|
-
return this.getPrice();
|
270
|
-
}
|
271
|
-
};
|
272
|
-
|
273
|
-
this.getOriginalPrice = function() {
|
274
|
-
return this.priceType ? this.priceMap[this.priceType] : null;
|
275
|
-
};
|
276
|
-
|
277
|
-
this.addPricing = function(type, price) {
|
278
|
-
this.priceMap[type] = price;
|
279
|
-
};
|
280
|
-
|
281
|
-
this.addPricingFromStatus = function(productStatus, priceType) {
|
282
|
-
let modified = false;
|
283
|
-
|
284
|
-
if (!priceType) {
|
285
|
-
priceType = this.priceType;
|
286
|
-
}
|
287
|
-
|
288
|
-
// previous code stored sku as all caps
|
289
|
-
const productStatusSku = productStatus.SKU || productStatus.sku;
|
290
|
-
if (productStatusSku === this.sku) {
|
291
|
-
this.globalProductID = productStatus.globalProductID;
|
292
|
-
this.status = productStatus.status;
|
293
|
-
this.availableQuantity = productStatus.availableQuantity;
|
294
|
-
this.maxQuantity = productStatus.maxQuantity || 999;
|
295
|
-
this.locallyProduced = productStatus.locallyProduced || false;
|
296
|
-
if (productStatus.backordered) {
|
297
|
-
this.backOrderDate = productStatus.backorderedAvailableDate;
|
298
|
-
}
|
299
|
-
if (productStatus.price) {
|
300
|
-
this.setPoints(productStatus.price.PTS);
|
301
|
-
Object.keys(productStatus.price).forEach((priceKey) => {
|
302
|
-
this.addPricing(priceKey, productStatus.price[priceKey]);
|
303
|
-
}, this);
|
304
|
-
}
|
305
|
-
if (productStatus.psv) {
|
306
|
-
Object.keys(productStatus.psv).forEach((psvKey) => {
|
307
|
-
this.addPvWithType(psvKey, productStatus.psv[psvKey]);
|
308
|
-
}, this);
|
309
|
-
}
|
310
|
-
if (productStatus.csv) {
|
311
|
-
Object.keys(productStatus.csv).map((csvKey) => {
|
312
|
-
return this.addCvWithType(csvKey, productStatus.csv[csvKey]);
|
313
|
-
}, this);
|
314
|
-
}
|
315
|
-
this.orderTypes = ProductUtils.mergeOrderTypes(this.orderTypes, productStatus.orderType);
|
316
|
-
if(productStatus.childSkus) {
|
317
|
-
this.childSkus = productStatus.childSkus;
|
318
|
-
}
|
319
|
-
this.setPriceAndPvFromType(priceType);
|
320
|
-
modified = true;
|
321
|
-
} else {
|
322
|
-
let variant = this.getVariant(productStatusSku);
|
323
|
-
|
324
|
-
if (variant) {
|
325
|
-
if (variant.addPricingFromStatus(productStatus, priceType)) {
|
326
|
-
variant.setMarketAttributes(productStatus);
|
327
|
-
updateBaseRanges(this, variant);
|
328
|
-
modified = true;
|
329
|
-
}
|
330
|
-
}
|
331
|
-
}
|
332
|
-
|
333
|
-
return modified;
|
334
|
-
};
|
335
|
-
|
336
|
-
this.addPvWithType = function(type, pv) {
|
337
|
-
this.pvMap[type] = pv;
|
338
|
-
};
|
339
|
-
|
340
|
-
this.addCvWithType = function(type, cv) {
|
341
|
-
this.cvMap[type] = cv;
|
342
|
-
};
|
343
|
-
|
344
|
-
this.getPricing = function(type) {
|
345
|
-
let retVal = null;
|
346
|
-
|
347
|
-
if (type) {
|
348
|
-
retVal = this.priceMap[type];
|
349
|
-
|
350
|
-
if (!retVal && isAdrType(type)) {
|
351
|
-
retVal = this.priceMap[getOppisiteAdrType(type)];
|
352
|
-
}
|
353
|
-
}
|
354
|
-
return retVal;
|
355
|
-
};
|
356
|
-
|
357
|
-
this.getEventPriceTypes = () => {
|
358
|
-
const eventPriceTypes = [];
|
359
|
-
|
360
|
-
Object.keys(this.priceMap).forEach(priceTypeKey => {
|
361
|
-
const eventPriceType = priceTypeKey.substring(0, priceTypeKey.indexOf(`-${this.priceType}`));
|
362
|
-
|
363
|
-
if (eventPriceType) {
|
364
|
-
eventPriceTypes.push(eventPriceType);
|
365
|
-
}
|
366
|
-
});
|
367
|
-
|
368
|
-
return eventPriceTypes;
|
369
|
-
};
|
370
|
-
|
371
|
-
this.getPvWithType = function(type) {
|
372
|
-
let rv = this.pvMap[type];
|
373
|
-
if (rv == null) {
|
374
|
-
// Assumption: we always have WWHL from the service
|
375
|
-
// default to wholesale if a PV of a particular type is not there
|
376
|
-
rv = this.pvMap[PriceType.WWHL];
|
377
|
-
}
|
378
|
-
return rv;
|
379
|
-
};
|
380
|
-
|
381
|
-
this.getCvWithType = function(type) {
|
382
|
-
let rv = this.cvMap[type];
|
383
|
-
if (rv == null) {
|
384
|
-
rv = this.cvMap[PriceType.WWHL];
|
385
|
-
}
|
386
|
-
return rv;
|
387
|
-
};
|
388
|
-
|
389
|
-
this.hasAdrOption = function() {
|
390
|
-
return this.orderTypes["adr"];
|
391
|
-
};
|
392
|
-
|
393
|
-
this.isAdrOnly = function() {
|
394
|
-
return this.hasAdrOption() && !this.hasOrderOption();
|
395
|
-
};
|
396
|
-
|
397
|
-
this.hasMultipleOrderTypes = function() {
|
398
|
-
return this.hasOrderOption() && this.hasAdrOption();
|
399
|
-
};
|
400
|
-
|
401
|
-
this.hasOrderOption = function() {
|
402
|
-
return this.orderTypes["order"];
|
403
|
-
};
|
404
|
-
|
405
|
-
this.isDistributor = function() {
|
406
|
-
return this.custTypes.includes("10");
|
407
|
-
};
|
408
|
-
|
409
|
-
this.isCustomer = function() {
|
410
|
-
return this.custTypes.includes("20");
|
411
|
-
};
|
412
|
-
|
413
|
-
this.isPreferredCustomer = function() {
|
414
|
-
return this.custTypes.includes("30");
|
415
|
-
};
|
416
|
-
|
417
|
-
this.isBase = function() {
|
418
|
-
return this.sku.substring(2, 4) === "55";
|
419
|
-
};
|
420
|
-
|
421
|
-
this.isVariant = function() {
|
422
|
-
return this.baseSku.length > 0 && this.variantSkus().length === 0;
|
423
|
-
};
|
424
|
-
|
425
|
-
this.setVariant = function(variantProduct) {
|
426
|
-
if (variantProduct && variantProduct.sku) {
|
427
|
-
this.variants[variantProduct.sku] = variantProduct;
|
428
|
-
}
|
429
|
-
};
|
430
|
-
|
431
|
-
this.getVariant = function(sku) {
|
432
|
-
return this.variants[sku];
|
433
|
-
};
|
434
|
-
|
435
|
-
this.variantSkus = function() {
|
436
|
-
return Object.keys(this.variants);
|
437
|
-
};
|
438
|
-
|
439
|
-
this.getVariantsList = function() {
|
440
|
-
return Object.values(this.variants);
|
441
|
-
};
|
442
|
-
|
443
|
-
this.getMinPrice = function() {
|
444
|
-
return this.priceMap[`min-${this.priceType}`];
|
445
|
-
};
|
446
|
-
|
447
|
-
this.getMaxPrice = function() {
|
448
|
-
return this.priceMap[`max-${this.priceType}`];
|
449
|
-
};
|
450
|
-
|
451
|
-
this.getMinPv = function() {
|
452
|
-
return this.pvMap[`min-${this.priceType}`];
|
453
|
-
};
|
454
|
-
|
455
|
-
this.getMaxPv = function() {
|
456
|
-
return this.pvMap[`max-${this.priceType}`];
|
457
|
-
};
|
458
|
-
|
459
|
-
this.toJSON = function() {
|
460
|
-
let retData = {};
|
461
|
-
retData.sku = this.sku;
|
462
|
-
retData.globalProductID = this.globalProductID;
|
463
|
-
retData.title = this.title;
|
464
|
-
retData.country = this.country;
|
465
|
-
retData.language = this.lang;
|
466
|
-
retData.shortDescr = this.shortDescr;
|
467
|
-
retData.longDescr = this.longDescr;
|
468
|
-
retData.fullImage = this.fullImage;
|
469
|
-
retData.imageAltText = this.imageAltText;
|
470
|
-
retData.productCarouselImages = this.productCarouselImages;
|
471
|
-
retData.thumbnail = this.thumbnail;
|
472
|
-
retData.ingredients = this.ingredients;
|
473
|
-
retData.benefits = this.benefits;
|
474
|
-
retData.usage = this.usage;
|
475
|
-
retData.resources = this.resources;
|
476
|
-
retData.videos = this.videos;
|
477
|
-
retData.movie = this.movie;
|
478
|
-
retData.youtube = this.youtube;
|
479
|
-
retData.salesEventText = this.salesEventText;
|
480
|
-
retData.contentSection = this.contentSection;
|
481
|
-
retData.scanQualified = this.scanQualified;
|
482
|
-
retData.availableQuantity = this.availableQuantity;
|
483
|
-
retData.maxQuantity = this.maxQuantity;
|
484
|
-
retData.points = this.points;
|
485
|
-
retData.cv = this.cv;
|
486
|
-
retData.pv = this.pv;
|
487
|
-
retData.priceType = this.priceType;
|
488
|
-
retData.price = this.price;
|
489
|
-
retData.priceMap = this.priceMap;
|
490
|
-
retData.cvMap = this.cvMap;
|
491
|
-
retData.pvMap = this.pvMap;
|
492
|
-
retData.orderTypes = this.orderTypes;
|
493
|
-
retData.childSkus = this.childSkus;
|
494
|
-
retData.custTypes = this.custTypes;
|
495
|
-
retData.division = this.division;
|
496
|
-
retData.backOrderDate = this.backOrderDate;
|
497
|
-
retData.locallyProduced = this.locallyProduced;
|
498
|
-
retData.agelocme = this.agelocme ? this.agelocme.toJSON() : null;
|
499
|
-
retData.count = this.count;
|
500
|
-
retData.flavor = this.flavor;
|
501
|
-
retData.size = this.size;
|
502
|
-
retData.shade = this.shade;
|
503
|
-
retData.status = this.status;
|
504
|
-
retData.variantType = this.variantType;
|
505
|
-
retData.variantDropdownLabel = this.variantDropdownLabel;
|
506
|
-
retData.variantDropdownPlaceholder = this.variantDropdownPlaceholder;
|
507
|
-
retData.variantsLabel = this.variantsLabel;
|
508
|
-
retData.groupOffer = this.groupOffer;
|
509
|
-
retData.personalOffer = this.personalOffer;
|
510
|
-
retData.savedEventName = this.savedEventName;
|
511
|
-
retData.salesLabel = this.salesLabel;
|
512
|
-
retData.eventName = this.eventName;
|
513
|
-
retData.sizeWeight = this.sizeWeight;
|
514
|
-
retData.nettoWeight = this.nettoWeight;
|
515
|
-
retData.productLabels = this.productLabels;
|
516
|
-
retData.variants = toVariantJSON(this.variants);
|
517
|
-
retData.searchScore = this.searchScore;
|
518
|
-
retData.isExclusive = this.isExclusive;
|
519
|
-
retData.marketAttributes = this.marketAttributes;
|
520
|
-
retData.restrictedMarkets = this.restrictedMarkets;
|
521
|
-
retData.addOns = this.addOns;
|
522
|
-
|
523
|
-
return retData;
|
524
|
-
};
|
525
|
-
|
526
|
-
this.setMeCommerceProductData = function(/*productData*/) {
|
527
|
-
console.error("setMeCommerceProductData is deprecated!");
|
528
|
-
};
|
529
|
-
|
530
|
-
this.setBaseUrl = function(baseUrl) {
|
531
|
-
this.thumbnail = ProductUtils.applyBaseUrl(this.thumbnail, baseUrl);
|
532
|
-
this.fullImage = ProductUtils.applyBaseUrl(this.fullImage, baseUrl);
|
533
|
-
|
534
|
-
if (this.isBase()) {
|
535
|
-
for (const variantSku in this.variants) {
|
536
|
-
const variant = this.variants[variantSku];
|
537
|
-
variant.setBaseUrl(baseUrl);
|
538
|
-
}
|
539
|
-
}
|
540
|
-
};
|
541
|
-
|
542
|
-
this.setProductData = function(productData) {
|
543
|
-
let data;
|
544
|
-
|
545
|
-
if (productData) {
|
546
|
-
if (productData instanceof eqProduct) {
|
547
|
-
data = productData.toJSON();
|
548
|
-
} else {
|
549
|
-
data = productData;
|
550
|
-
}
|
551
|
-
if (data.sku) {
|
552
|
-
this.sku = data.sku;
|
553
|
-
}
|
554
|
-
this.globalProductID = data.globalProductID || '';
|
555
|
-
this.title = data.title;
|
556
|
-
this.country = data.country;
|
557
|
-
this.lang = data.language;
|
558
|
-
this.shortDescr = data.shortDescr;
|
559
|
-
this.longDescr = data.longDescr;
|
560
|
-
this.isExclusive = isTrue(data.isExclusive);
|
561
|
-
|
562
|
-
// WARNING: Browser Detection will need to be handled in the client
|
563
|
-
// if (!BrowserDetection.isEdge() && !BrowserDetection.isFirefox()) {
|
564
|
-
// this.fullImage = data.fullImage ? `${data.fullImage.split('?')[0]}?format=pjpg` : undefined;
|
565
|
-
// this.thumbnail = data.thumbnail ? `${data.thumbnail.split('?')[0]}?format=pjpg` : undefined;
|
566
|
-
// }
|
567
|
-
this.fullImage = data.fullImage;
|
568
|
-
this.thumbnail = data.thumbnail;
|
569
|
-
this.imageAltText = data.imageAltText;
|
570
|
-
this.productCarouselImages = data.productCarouselImages;
|
571
|
-
|
572
|
-
this.ingredients = data.ingredients;
|
573
|
-
this.benefits = data.benefits;
|
574
|
-
this.usage = data.usage;
|
575
|
-
this.resources = data.resources;
|
576
|
-
this.videos = data.videos;
|
577
|
-
this.movie = data.movie;
|
578
|
-
this.youtube = data.youtube;
|
579
|
-
this.salesEventText = data.salesEventText;
|
580
|
-
this.contentSection = data.contentSection;
|
581
|
-
this.scanQualified = data.scanQualified;
|
582
|
-
this.status = data.status ? data.status : this.status;
|
583
|
-
if (data.availableQuantity) {
|
584
|
-
this.availableQuantity = data.availableQuantity;
|
585
|
-
}
|
586
|
-
if (data.maxQuantity >= 0) {
|
587
|
-
this.maxQuantity = data.maxQuantity;
|
588
|
-
}
|
589
|
-
if (data.points) {
|
590
|
-
this.setPoints(data.points);
|
591
|
-
}
|
592
|
-
if (data.cv) {
|
593
|
-
this.setCv(data.cv);
|
594
|
-
}
|
595
|
-
if (data.pv) {
|
596
|
-
this.setPv(data.pv);
|
597
|
-
}
|
598
|
-
if (data.price) {
|
599
|
-
this.setPrice(data.price);
|
600
|
-
}
|
601
|
-
if (data.formattedPrice) {
|
602
|
-
this.setFormattedPrice(data.formattedPrice);
|
603
|
-
}
|
604
|
-
if (data.priceType) {
|
605
|
-
this.priceType = data.priceType;
|
606
|
-
}
|
607
|
-
this.locallyProduced = data.locallyProduced;
|
608
|
-
this.count = productData.count;
|
609
|
-
this.flavor = productData.flavor;
|
610
|
-
this.size = productData.size;
|
611
|
-
this.shade = productData.shade;
|
612
|
-
this.variantType = productData.variantType;
|
613
|
-
this.variantDropdownLabel = productData.variantDropdownLabel;
|
614
|
-
this.variantDropdownPlaceholder = productData.variantDropdownPlaceholder;
|
615
|
-
this.variantsLabel = productData.variantsLabel;
|
616
|
-
this.groupOffer = productData.groupOffer;
|
617
|
-
this.personalOffer = productData.personalOffer;
|
618
|
-
this.baseSku = productData.baseSku ? productData.baseSku : "";
|
619
|
-
this.savedEventName = productData.savedEventName;
|
620
|
-
this.sizeWeight = productData.sizeWeight;
|
621
|
-
this.nettoWeight = productData.nettoWeight;
|
622
|
-
this.productLabels = productData.productLabels;
|
623
|
-
this.salesLabel = productData.salesLabel;
|
624
|
-
this.eventName = productData.eventName;
|
625
|
-
this.variants = fromVariantJSON(this, productData.variants);
|
626
|
-
this.searchScore = productData.searchScore ? productData.searchScore : 0;
|
627
|
-
this.marketAttributes = productData.marketAttributes;
|
628
|
-
this.addOns = productData.addOns || [];
|
629
|
-
this.restrictedMarkets = productData.restrictedMarkets || [];
|
630
|
-
|
631
|
-
if (data.priceType) {
|
632
|
-
this.addPricing(data.priceType, data.price);
|
633
|
-
this.addPvWithType(data.priceType, data.pv);
|
634
|
-
this.addCvWithType(data.priceType, data.cv);
|
635
|
-
}
|
636
|
-
this.priceMap =
|
637
|
-
data.priceMap && Object.keys(data.priceMap).length > 0
|
638
|
-
? data.priceMap
|
639
|
-
: this.priceMap;
|
640
|
-
this.cvMap =
|
641
|
-
data.cvMap && Object.keys(data.cvMap).length > 0
|
642
|
-
? data.cvMap
|
643
|
-
: this.cvMap;
|
644
|
-
this.pvMap =
|
645
|
-
data.pvMap && Object.keys(data.pvMap).length > 0
|
646
|
-
? data.pvMap
|
647
|
-
: this.pvMap;
|
648
|
-
this.orderTypes = ProductUtils.mergeOrderTypes(this.orderTypes, data.orderTypes);
|
649
|
-
if(data.childSkus) {
|
650
|
-
this.childSkus = data.childSkus;
|
651
|
-
}
|
652
|
-
this.custTypes = data.custTypes || [];
|
653
|
-
|
654
|
-
this.division = data.division;
|
655
|
-
this.backOrderDate = data.backOrderDate;
|
656
|
-
|
657
|
-
if (data.agelocme) {
|
658
|
-
this.agelocme = new Agelocme(data.agelocme);
|
659
|
-
}
|
660
|
-
}
|
661
|
-
};
|
662
|
-
|
663
|
-
this.isEmpty = function() {
|
664
|
-
return (
|
665
|
-
isFieldEmpty(this.sku) &&
|
666
|
-
isFieldEmpty(this.title) &&
|
667
|
-
isFieldEmpty(this.country) &&
|
668
|
-
isFieldEmpty(this.lang) &&
|
669
|
-
isFieldEmpty(this.shortDescr) &&
|
670
|
-
isFieldEmpty(this.longDescr) &&
|
671
|
-
isFieldEmpty(this.fullImage) &&
|
672
|
-
isFieldEmpty(this.thumbnail) &&
|
673
|
-
isFieldEmpty(this.points) &&
|
674
|
-
isFieldEmpty(this.cv) &&
|
675
|
-
isFieldEmpty(this.pv) &&
|
676
|
-
Object.keys(this.priceMap).length === 0
|
677
|
-
);
|
678
|
-
};
|
679
|
-
|
680
|
-
function isAdrType(priceType) {
|
681
|
-
return (
|
682
|
-
priceType === PriceType.WADW ||
|
683
|
-
priceType === PriceType.ADW ||
|
684
|
-
priceType === PriceType.WADR ||
|
685
|
-
priceType === PriceType.ADR
|
686
|
-
);
|
687
|
-
}
|
688
|
-
|
689
|
-
function getOppisiteAdrType(priceType) {
|
690
|
-
let retVal = priceType;
|
691
|
-
|
692
|
-
switch (priceType) {
|
693
|
-
case PriceType.WADW:
|
694
|
-
retVal = PriceType.ADW;
|
695
|
-
break;
|
696
|
-
case PriceType.ADW:
|
697
|
-
retVal = PriceType.WADW;
|
698
|
-
break;
|
699
|
-
case PriceType.WADR:
|
700
|
-
retVal = PriceType.ADR;
|
701
|
-
break;
|
702
|
-
case PriceType.ADR:
|
703
|
-
retVal = PriceType.WADR;
|
704
|
-
break;
|
705
|
-
}
|
706
|
-
return retVal;
|
707
|
-
}
|
708
|
-
|
709
|
-
function toVariantJSON(variants) {
|
710
|
-
let json = {};
|
711
|
-
|
712
|
-
Object.keys(variants).forEach((sku) => {
|
713
|
-
json[sku] = variants[sku].toJSON();
|
714
|
-
});
|
715
|
-
|
716
|
-
return json;
|
717
|
-
}
|
718
|
-
|
719
|
-
function fromVariantJSON(baseProduct, variantsJson) {
|
720
|
-
let variants = {};
|
721
|
-
|
722
|
-
if (variantsJson) {
|
723
|
-
for (const variantSku of Object.keys(variantsJson)) {
|
724
|
-
const variantJson = variantsJson[variantSku];
|
725
|
-
const variant = new eqProduct(variantJson);
|
726
|
-
|
727
|
-
variant.baseSku = baseProduct.sku;
|
728
|
-
|
729
|
-
variants[variantSku] = variant;
|
730
|
-
}
|
731
|
-
}
|
732
|
-
|
733
|
-
return variants;
|
734
|
-
}
|
735
|
-
|
736
|
-
function updateBaseRanges(scope, variant) {
|
737
|
-
Object.keys(variant.priceMap).forEach((priceType) => {
|
738
|
-
let minPriceType = `min-${priceType}`,
|
739
|
-
maxPriceType = `max-${priceType}`;
|
740
|
-
|
741
|
-
scope.priceMap[minPriceType] = Math.min(
|
742
|
-
scope.priceMap[minPriceType] || variant.priceMap[priceType],
|
743
|
-
variant.priceMap[priceType]
|
744
|
-
);
|
745
|
-
scope.priceMap[maxPriceType] = Math.max(
|
746
|
-
scope.priceMap[maxPriceType] || 0.0,
|
747
|
-
variant.priceMap[priceType]
|
748
|
-
);
|
749
|
-
|
750
|
-
scope.pvMap[minPriceType] = Math.min(
|
751
|
-
scope.pvMap[minPriceType] || variant.pvMap[priceType],
|
752
|
-
variant.pvMap[priceType]
|
753
|
-
);
|
754
|
-
scope.pvMap[maxPriceType] = Math.max(
|
755
|
-
scope.pvMap[maxPriceType] || 0.0,
|
756
|
-
variant.pvMap[priceType]
|
757
|
-
);
|
758
|
-
});
|
759
|
-
}
|
760
|
-
|
761
|
-
function ensureFloatVal(val, acceptString) {
|
762
|
-
let intVal;
|
763
|
-
if (typeof val === "number") {
|
764
|
-
intVal = val;
|
765
|
-
} else if (typeof val === "string") {
|
766
|
-
intVal = Number(val.replace(/[^0-9.]+/g, ""));
|
767
|
-
if (isNaN(intVal) && acceptString) {
|
768
|
-
intVal = val;
|
769
|
-
}
|
770
|
-
}
|
771
|
-
return intVal;
|
772
|
-
}
|
773
|
-
|
774
|
-
function isFieldEmpty(fieldValue) {
|
775
|
-
return (
|
776
|
-
fieldValue === null || fieldValue === undefined || fieldValue.length === 0
|
777
|
-
);
|
778
|
-
}
|
779
|
-
|
780
|
-
let activeEvents = [];
|
781
|
-
function getEventPricing(scope, priceType, _activeEvents = null) {
|
782
|
-
let eventNames = scope.savedEventName
|
783
|
-
? [scope.savedEventName]
|
784
|
-
: _activeEvents || activeEvents;
|
785
|
-
let retVal = { eventName: null };
|
786
|
-
|
787
|
-
eventNames.forEach((event) => {
|
788
|
-
let _eventPriceType = `${event}-${priceType}`;
|
789
|
-
|
790
|
-
if (scope.getPricing(_eventPriceType)) {
|
791
|
-
retVal.price = scope.getPricing(_eventPriceType);
|
792
|
-
retVal.cv = scope.getCvWithType(_eventPriceType);
|
793
|
-
retVal.pv = scope.getPvWithType(_eventPriceType);
|
794
|
-
retVal.priceType = _eventPriceType;
|
795
|
-
retVal.eventName = scope.effectiveEventName = event;
|
796
|
-
}
|
797
|
-
});
|
798
|
-
|
799
|
-
return retVal;
|
800
|
-
}
|
801
|
-
|
802
|
-
// WARNING: Product events will need to be handled in the client
|
803
|
-
// $.getValue(events.salesevent.ACTIVE_EVENTS, _activeEvents => {
|
804
|
-
// if (_activeEvents) {
|
805
|
-
// activeEvents = _activeEvents;
|
806
|
-
// }
|
807
|
-
// }, true);
|
808
|
-
|
809
|
-
this.setProductData(productData);
|
810
|
-
};
|
811
|
-
|
812
|
-
module.exports = eqProduct;
|