@nuskin/ns-product-lib 2.5.0-cx24-32821.3 → 2.5.0-cx24-32824.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +4 -28
- package/package.json +1 -1
- package/src/product.js +62 -63
package/CHANGELOG.md
CHANGED
@@ -1,35 +1,11 @@
|
|
1
|
-
# [2.5.0-cx24-
|
1
|
+
# [2.5.0-cx24-32824.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.19...v2.5.0-cx24-32824.1) (2023-02-28)
|
2
2
|
|
3
3
|
|
4
4
|
### Fix
|
5
5
|
|
6
|
-
*
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
### Fix
|
12
|
-
|
13
|
-
* Get test environment if not PROD ([ddbe173](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/ddbe173f59ce867476c39bc75034f605fe351cd3))
|
14
|
-
|
15
|
-
# [2.5.0-cx24-32821.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.19...v2.5.0-cx24-32821.1) (2023-02-02)
|
16
|
-
|
17
|
-
|
18
|
-
### Fix
|
19
|
-
|
20
|
-
* Get test environment if not PROD ([8bf5d3c](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/8bf5d3cabc3de850f3742abf7a27b4751e00d100))
|
21
|
-
* Get test environment if not PROD ([f41db9c](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/f41db9cee5aa0dde3885fc45ab8a391a325ab9a1))
|
22
|
-
|
23
|
-
### Release
|
24
|
-
|
25
|
-
* Automated changes by GitLab pipeline [skip ci] ([a1b0259](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/a1b02590dd8aec0f2361d58848d6a35f3f654664))
|
26
|
-
|
27
|
-
# [2.5.0-cx24-3282.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.19...v2.5.0-cx24-3282.1) (2023-02-02)
|
28
|
-
|
29
|
-
|
30
|
-
### Fix
|
31
|
-
|
32
|
-
* Get test environment if not PROD ([f41db9c](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/f41db9cee5aa0dde3885fc45ab8a391a325ab9a1))
|
6
|
+
* Do not set availability from status ([e28d7f3](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/e28d7f3b6e03d21f6de7ec5e31d79405f533b5bc))
|
7
|
+
* Do not set availability from status ([47f13e5](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/47f13e51236df2870b589d6b5d8b4902f7357c56))
|
8
|
+
* Get test environment if not PROD ([913abb6](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/913abb61f8bc6aa8a2cb271d67de08f2f9505c5e))
|
33
9
|
|
34
10
|
# [2.5.0-cx24-2179.2.19](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.5.0-cx24-2179.2.18...v2.5.0-cx24-2179.2.19) (2023-01-27)
|
35
11
|
|
package/package.json
CHANGED
package/src/product.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
const { isTrue }
|
3
|
+
const { isTrue } = require("@nuskin/ns-common-lib");
|
4
4
|
|
5
5
|
const ProductUtils = require("./productUtils.js");
|
6
6
|
|
@@ -8,7 +8,7 @@ const Agelocme = require("./agelocme.js");
|
|
8
8
|
const PriceType = require("./models/priceType.js");
|
9
9
|
const ProductStatus = require("./models/productStatus.js");
|
10
10
|
|
11
|
-
const Product = function(productData) {
|
11
|
+
const Product = function (productData) {
|
12
12
|
this.priceMap = {};
|
13
13
|
this.pvMap = {};
|
14
14
|
this.cvMap = {};
|
@@ -77,13 +77,13 @@ const Product = function(productData) {
|
|
77
77
|
this.inventory = "";
|
78
78
|
this.equinoxProductId = "";
|
79
79
|
|
80
|
-
this.setMarketAttributes = function(productStatus) {
|
80
|
+
this.setMarketAttributes = function (productStatus) {
|
81
81
|
if (productStatus.marketAttributes) {
|
82
82
|
this.marketAttributes = productStatus.marketAttributes;
|
83
83
|
}
|
84
84
|
};
|
85
85
|
|
86
|
-
this.getAgelocmeKeyPart = function() {
|
86
|
+
this.getAgelocmeKeyPart = function () {
|
87
87
|
let keyPart = null;
|
88
88
|
if (this.agelocme) {
|
89
89
|
keyPart =
|
@@ -97,27 +97,27 @@ const Product = function(productData) {
|
|
97
97
|
return keyPart;
|
98
98
|
};
|
99
99
|
|
100
|
-
this.getHighlightedSku = function() {
|
100
|
+
this.getHighlightedSku = function () {
|
101
101
|
let rv = this.sku;
|
102
102
|
if (this.highlightedSku) rv = this.highlightedSku;
|
103
103
|
return rv;
|
104
104
|
};
|
105
105
|
|
106
|
-
this.getProductSearchTitle = function() {
|
106
|
+
this.getProductSearchTitle = function () {
|
107
107
|
if (this.agelocme && this.agelocme.label) {
|
108
108
|
return this.agelocme.label;
|
109
109
|
}
|
110
110
|
return this.title;
|
111
111
|
};
|
112
112
|
|
113
|
-
this.getProductSearchSku = function() {
|
113
|
+
this.getProductSearchSku = function () {
|
114
114
|
if (this.agelocme && this.agelocme.code) {
|
115
115
|
return this.agelocme.code;
|
116
116
|
}
|
117
117
|
return this.getHighlightedSku();
|
118
118
|
};
|
119
119
|
|
120
|
-
this.getDescription = function() {
|
120
|
+
this.getDescription = function () {
|
121
121
|
let description = this.longDescr;
|
122
122
|
if (!description || description.length === 0) {
|
123
123
|
return this.shortDescr;
|
@@ -125,7 +125,7 @@ const Product = function(productData) {
|
|
125
125
|
return description;
|
126
126
|
};
|
127
127
|
|
128
|
-
this.setFullImage = function(fullImage) {
|
128
|
+
this.setFullImage = function (fullImage) {
|
129
129
|
if (fullImage) {
|
130
130
|
this.fullImage = fullImage.replace("http:", "https:");
|
131
131
|
} else {
|
@@ -133,19 +133,19 @@ const Product = function(productData) {
|
|
133
133
|
}
|
134
134
|
};
|
135
135
|
|
136
|
-
this.getFullImage = function() {
|
136
|
+
this.getFullImage = function () {
|
137
137
|
return this.fullImage ? this.fullImage.replace("http:", "https:") : "";
|
138
138
|
};
|
139
139
|
|
140
|
-
this.setProductCarouselImages = function(productCarouselImages) {
|
140
|
+
this.setProductCarouselImages = function (productCarouselImages) {
|
141
141
|
this.productCarouselImages = productCarouselImages;
|
142
142
|
};
|
143
143
|
|
144
|
-
this.getProductCarouselImages = function() {
|
144
|
+
this.getProductCarouselImages = function () {
|
145
145
|
return this.productCarouselImages;
|
146
146
|
};
|
147
147
|
|
148
|
-
this.setImageAltText = function(altText) {
|
148
|
+
this.setImageAltText = function (altText) {
|
149
149
|
if (altText) {
|
150
150
|
this.imageAltText = altText;
|
151
151
|
} else {
|
@@ -153,11 +153,11 @@ const Product = function(productData) {
|
|
153
153
|
}
|
154
154
|
};
|
155
155
|
|
156
|
-
this.getImageAltText = function() {
|
156
|
+
this.getImageAltText = function () {
|
157
157
|
return this.imageAltText || this.title;
|
158
158
|
};
|
159
159
|
|
160
|
-
this.setThumbnail = function(thumbnail) {
|
160
|
+
this.setThumbnail = function (thumbnail) {
|
161
161
|
if (thumbnail) {
|
162
162
|
this.thumbnail = thumbnail.replace("http:", "https:");
|
163
163
|
} else {
|
@@ -165,7 +165,7 @@ const Product = function(productData) {
|
|
165
165
|
}
|
166
166
|
};
|
167
167
|
|
168
|
-
this.setThumbnailFromSku = function(sku) {
|
168
|
+
this.setThumbnailFromSku = function (sku) {
|
169
169
|
// WARNING: Base URL will need to be handled in the client (call setBaseUrl)
|
170
170
|
// eslint-disable-next-line max-len
|
171
171
|
// this.thumbnail = `${RunConfigService.getBaseUrl()}/content/products/${ProductUtils.getTokenizedSku(sku)}/jcr:content/fullImage.img.100.100.png`;
|
@@ -175,43 +175,43 @@ const Product = function(productData) {
|
|
175
175
|
)}/jcr:content/fullImage.img.100.100.png`;
|
176
176
|
};
|
177
177
|
|
178
|
-
this.getThumbnail = function() {
|
178
|
+
this.getThumbnail = function () {
|
179
179
|
return this.thumbnail ? this.thumbnail.replace("http:", "https:") : "";
|
180
180
|
};
|
181
181
|
|
182
|
-
this.hasAvailableQuantity = function(qty = 1) {
|
182
|
+
this.hasAvailableQuantity = function (qty = 1) {
|
183
183
|
return Math.min(this.maxQuantity, this.availableQuantity) >= qty;
|
184
184
|
};
|
185
185
|
|
186
|
-
this.setPoints = function(points) {
|
186
|
+
this.setPoints = function (points) {
|
187
187
|
this.points = ensureFloatVal(points) || "";
|
188
188
|
};
|
189
189
|
|
190
|
-
this.getPointsFixed = function() {
|
190
|
+
this.getPointsFixed = function () {
|
191
191
|
return parseFloat(this.points).toFixed(2);
|
192
192
|
};
|
193
193
|
|
194
|
-
this.setCv = function(cv) {
|
194
|
+
this.setCv = function (cv) {
|
195
195
|
this.cv = ensureFloatVal(cv) || "";
|
196
196
|
};
|
197
197
|
|
198
|
-
this.getCvFixed = function() {
|
198
|
+
this.getCvFixed = function () {
|
199
199
|
return parseFloat(this.cv).toFixed(2);
|
200
200
|
};
|
201
201
|
|
202
|
-
this.setPv = function(pv) {
|
202
|
+
this.setPv = function (pv) {
|
203
203
|
this.pv = ensureFloatVal(pv) || "";
|
204
204
|
};
|
205
205
|
|
206
|
-
this.getPvFixed = function() {
|
206
|
+
this.getPvFixed = function () {
|
207
207
|
return parseFloat(this.pv || 0).toFixed(2);
|
208
208
|
};
|
209
209
|
|
210
|
-
this.setPrice = function(price) {
|
210
|
+
this.setPrice = function (price) {
|
211
211
|
this.price = ensureFloatVal(price, true);
|
212
212
|
};
|
213
213
|
|
214
|
-
this.setFormattedPrice = function(formattedPrice) {
|
214
|
+
this.setFormattedPrice = function (formattedPrice) {
|
215
215
|
this.formattedPrice = formattedPrice;
|
216
216
|
};
|
217
217
|
|
@@ -220,13 +220,13 @@ const Product = function(productData) {
|
|
220
220
|
* added to the cart the event pricing needs to be remembered if toggling between
|
221
221
|
* pricetypes with event pricing and pricetype without event pricing
|
222
222
|
*/
|
223
|
-
this.lockEventName = function() {
|
223
|
+
this.lockEventName = function () {
|
224
224
|
if (!this.savedEventName && this.eventName) {
|
225
225
|
this.savedEventName = this.eventName;
|
226
226
|
}
|
227
227
|
};
|
228
228
|
|
229
|
-
this.setPriceAndPvFromType = function(_priceType, _activeEvents = null, option = {}) {
|
229
|
+
this.setPriceAndPvFromType = function (_priceType, _activeEvents = null, option = {}) {
|
230
230
|
// WARNING: priceType needs to be handled client-side
|
231
231
|
// const priceType = ConfigService.getMarketConfig().showWholeSalePricing && !AccountManager.isLoggedIn()
|
232
232
|
// ? PriceType.WWHL
|
@@ -271,11 +271,11 @@ const Product = function(productData) {
|
|
271
271
|
return changed;
|
272
272
|
};
|
273
273
|
|
274
|
-
this.getPrice = function() {
|
274
|
+
this.getPrice = function () {
|
275
275
|
return this.price ? this.price : 0;
|
276
276
|
};
|
277
277
|
|
278
|
-
this.getPriceFixed = function() {
|
278
|
+
this.getPriceFixed = function () {
|
279
279
|
if (typeof this.price === "number") {
|
280
280
|
return parseFloat(this.price.toFixed(2));
|
281
281
|
} else {
|
@@ -283,15 +283,15 @@ const Product = function(productData) {
|
|
283
283
|
}
|
284
284
|
};
|
285
285
|
|
286
|
-
this.getOriginalPrice = function() {
|
286
|
+
this.getOriginalPrice = function () {
|
287
287
|
return this.priceType ? this.priceMap[this.priceType] : null;
|
288
288
|
};
|
289
289
|
|
290
|
-
this.addPricing = function(type, price) {
|
290
|
+
this.addPricing = function (type, price) {
|
291
291
|
this.priceMap[type] = price;
|
292
292
|
};
|
293
293
|
|
294
|
-
this.addPricingFromStatus = function(productStatus, priceType, option ={}) {
|
294
|
+
this.addPricingFromStatus = function (productStatus, priceType, option = {}) {
|
295
295
|
let modified = false;
|
296
296
|
|
297
297
|
if (!priceType) {
|
@@ -303,7 +303,6 @@ const Product = function(productData) {
|
|
303
303
|
if (productStatusSku === this.sku) {
|
304
304
|
this.globalProductID = productStatus.globalProductID;
|
305
305
|
this.status = productStatus.status;
|
306
|
-
this.availableQuantity = productStatus.availableQuantity;
|
307
306
|
this.maxQuantity = productStatus.maxQuantity || 999;
|
308
307
|
this.locallyProduced = productStatus.locallyProduced || false;
|
309
308
|
if (productStatus.backordered) {
|
@@ -326,7 +325,7 @@ const Product = function(productData) {
|
|
326
325
|
}, this);
|
327
326
|
}
|
328
327
|
this.orderTypes = ProductUtils.mergeOrderTypes(this.orderTypes, productStatus.orderType);
|
329
|
-
if(productStatus.childSkus) {
|
328
|
+
if (productStatus.childSkus) {
|
330
329
|
this.childSkus = productStatus.childSkus;
|
331
330
|
}
|
332
331
|
this.setPriceAndPvFromType(priceType, null, option);
|
@@ -346,15 +345,15 @@ const Product = function(productData) {
|
|
346
345
|
return modified;
|
347
346
|
};
|
348
347
|
|
349
|
-
this.addPvWithType = function(type, pv) {
|
348
|
+
this.addPvWithType = function (type, pv) {
|
350
349
|
this.pvMap[type] = pv;
|
351
350
|
};
|
352
351
|
|
353
|
-
this.addCvWithType = function(type, cv) {
|
352
|
+
this.addCvWithType = function (type, cv) {
|
354
353
|
this.cvMap[type] = cv;
|
355
354
|
};
|
356
355
|
|
357
|
-
this.getPricing = function(type) {
|
356
|
+
this.getPricing = function (type) {
|
358
357
|
let retVal = null;
|
359
358
|
|
360
359
|
if (type) {
|
@@ -381,7 +380,7 @@ const Product = function(productData) {
|
|
381
380
|
return eventPriceTypes;
|
382
381
|
};
|
383
382
|
|
384
|
-
this.getPvWithType = function(type) {
|
383
|
+
this.getPvWithType = function (type) {
|
385
384
|
let rv = this.pvMap[type];
|
386
385
|
if (rv == null) {
|
387
386
|
// Assumption: we always have WWHL from the service
|
@@ -391,7 +390,7 @@ const Product = function(productData) {
|
|
391
390
|
return rv;
|
392
391
|
};
|
393
392
|
|
394
|
-
this.getCvWithType = function(type) {
|
393
|
+
this.getCvWithType = function (type) {
|
395
394
|
let rv = this.cvMap[type];
|
396
395
|
if (rv == null) {
|
397
396
|
rv = this.cvMap[PriceType.WWHL];
|
@@ -399,77 +398,77 @@ const Product = function(productData) {
|
|
399
398
|
return rv;
|
400
399
|
};
|
401
400
|
|
402
|
-
this.hasAdrOption = function() {
|
401
|
+
this.hasAdrOption = function () {
|
403
402
|
return this.orderTypes["adr"];
|
404
403
|
};
|
405
404
|
|
406
|
-
this.isAdrOnly = function() {
|
405
|
+
this.isAdrOnly = function () {
|
407
406
|
return this.hasAdrOption() && !this.hasOrderOption();
|
408
407
|
};
|
409
408
|
|
410
|
-
this.hasMultipleOrderTypes = function() {
|
409
|
+
this.hasMultipleOrderTypes = function () {
|
411
410
|
return this.hasOrderOption() && this.hasAdrOption();
|
412
411
|
};
|
413
412
|
|
414
|
-
this.hasOrderOption = function() {
|
413
|
+
this.hasOrderOption = function () {
|
415
414
|
return this.orderTypes["order"];
|
416
415
|
};
|
417
416
|
|
418
|
-
this.isDistributor = function() {
|
417
|
+
this.isDistributor = function () {
|
419
418
|
return this.custTypes.includes("10");
|
420
419
|
};
|
421
420
|
|
422
|
-
this.isCustomer = function() {
|
421
|
+
this.isCustomer = function () {
|
423
422
|
return this.custTypes.includes("20");
|
424
423
|
};
|
425
424
|
|
426
|
-
this.isPreferredCustomer = function() {
|
425
|
+
this.isPreferredCustomer = function () {
|
427
426
|
return this.custTypes.includes("30");
|
428
427
|
};
|
429
428
|
|
430
|
-
this.isBase = function() {
|
429
|
+
this.isBase = function () {
|
431
430
|
return this.sku.substring(2, 4) === "55";
|
432
431
|
};
|
433
432
|
|
434
|
-
this.isVariant = function() {
|
433
|
+
this.isVariant = function () {
|
435
434
|
return this.baseSku.length > 0 && this.variantSkus().length === 0;
|
436
435
|
};
|
437
436
|
|
438
|
-
this.setVariant = function(variantProduct) {
|
437
|
+
this.setVariant = function (variantProduct) {
|
439
438
|
if (variantProduct && variantProduct.sku) {
|
440
439
|
this.variants[variantProduct.sku] = variantProduct;
|
441
440
|
}
|
442
441
|
};
|
443
442
|
|
444
|
-
this.getVariant = function(sku) {
|
443
|
+
this.getVariant = function (sku) {
|
445
444
|
return this.variants[sku];
|
446
445
|
};
|
447
446
|
|
448
|
-
this.variantSkus = function() {
|
447
|
+
this.variantSkus = function () {
|
449
448
|
return Object.keys(this.variants);
|
450
449
|
};
|
451
450
|
|
452
|
-
this.getVariantsList = function() {
|
451
|
+
this.getVariantsList = function () {
|
453
452
|
return Object.values(this.variants);
|
454
453
|
};
|
455
454
|
|
456
|
-
this.getMinPrice = function() {
|
455
|
+
this.getMinPrice = function () {
|
457
456
|
return this.priceMap[`min-${this.priceType}`];
|
458
457
|
};
|
459
458
|
|
460
|
-
this.getMaxPrice = function() {
|
459
|
+
this.getMaxPrice = function () {
|
461
460
|
return this.priceMap[`max-${this.priceType}`];
|
462
461
|
};
|
463
462
|
|
464
|
-
this.getMinPv = function() {
|
463
|
+
this.getMinPv = function () {
|
465
464
|
return this.pvMap[`min-${this.priceType}`];
|
466
465
|
};
|
467
466
|
|
468
|
-
this.getMaxPv = function() {
|
467
|
+
this.getMaxPv = function () {
|
469
468
|
return this.pvMap[`max-${this.priceType}`];
|
470
469
|
};
|
471
470
|
|
472
|
-
this.toJSON = function() {
|
471
|
+
this.toJSON = function () {
|
473
472
|
let retData = {};
|
474
473
|
retData.sku = this.sku;
|
475
474
|
retData.globalProductID = this.globalProductID;
|
@@ -538,11 +537,11 @@ const Product = function(productData) {
|
|
538
537
|
return retData;
|
539
538
|
};
|
540
539
|
|
541
|
-
this.setMeCommerceProductData = function(/*productData*/) {
|
540
|
+
this.setMeCommerceProductData = function (/*productData*/) {
|
542
541
|
console.error("setMeCommerceProductData is deprecated!");
|
543
542
|
};
|
544
543
|
|
545
|
-
this.setBaseUrl = function(baseUrl) {
|
544
|
+
this.setBaseUrl = function (baseUrl) {
|
546
545
|
this.thumbnail = ProductUtils.applyBaseUrl(this.thumbnail, baseUrl);
|
547
546
|
this.fullImage = ProductUtils.applyBaseUrl(this.fullImage, baseUrl);
|
548
547
|
|
@@ -554,7 +553,7 @@ const Product = function(productData) {
|
|
554
553
|
}
|
555
554
|
};
|
556
555
|
|
557
|
-
this.setProductData = function(productData) {
|
556
|
+
this.setProductData = function (productData) {
|
558
557
|
let data;
|
559
558
|
|
560
559
|
if (productData) {
|
@@ -662,7 +661,7 @@ const Product = function(productData) {
|
|
662
661
|
? data.pvMap
|
663
662
|
: this.pvMap;
|
664
663
|
this.orderTypes = ProductUtils.mergeOrderTypes(this.orderTypes, data.orderTypes);
|
665
|
-
if(data.childSkus) {
|
664
|
+
if (data.childSkus) {
|
666
665
|
this.childSkus = data.childSkus;
|
667
666
|
}
|
668
667
|
this.custTypes = data.custTypes || [];
|
@@ -678,7 +677,7 @@ const Product = function(productData) {
|
|
678
677
|
}
|
679
678
|
};
|
680
679
|
|
681
|
-
this.isEmpty = function() {
|
680
|
+
this.isEmpty = function () {
|
682
681
|
return (
|
683
682
|
isFieldEmpty(this.sku) &&
|
684
683
|
isFieldEmpty(this.title) &&
|