@nuskin/ns-product-lib 2.7.0-cx24-3702.1 → 2.7.0-cx24-3702.2
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 +7 -0
- package/package.json +1 -1
- package/src/product.js +65 -62
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [2.7.0-cx24-3702.2](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.7.0-cx24-3702.1...v2.7.0-cx24-3702.2) (2023-03-25)
|
2
|
+
|
3
|
+
|
4
|
+
### New
|
5
|
+
|
6
|
+
* adding properties variable to equinox product data ([46e2c7e](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/commit/46e2c7e4b5727d02ae31ccd62ec32ed73bdb6bc7))
|
7
|
+
|
1
8
|
# [2.7.0-cx24-3702.1](https://code.tls.nuskin.io/ns-am/product/js-libs/ns-product-lib/compare/v2.6.2...v2.7.0-cx24-3702.1) (2023-03-25)
|
2
9
|
|
3
10
|
|
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 = {};
|
@@ -76,14 +76,15 @@ const Product = function(productData) {
|
|
76
76
|
//@example "IN STOCK"
|
77
77
|
this.inventory = "";
|
78
78
|
this.equinoxProductId = "";
|
79
|
+
this.properties = {};
|
79
80
|
|
80
|
-
this.setMarketAttributes = function(productStatus) {
|
81
|
+
this.setMarketAttributes = function (productStatus) {
|
81
82
|
if (productStatus.marketAttributes) {
|
82
83
|
this.marketAttributes = productStatus.marketAttributes;
|
83
84
|
}
|
84
85
|
};
|
85
86
|
|
86
|
-
this.getAgelocmeKeyPart = function() {
|
87
|
+
this.getAgelocmeKeyPart = function () {
|
87
88
|
let keyPart = null;
|
88
89
|
if (this.agelocme) {
|
89
90
|
keyPart =
|
@@ -97,27 +98,27 @@ const Product = function(productData) {
|
|
97
98
|
return keyPart;
|
98
99
|
};
|
99
100
|
|
100
|
-
this.getHighlightedSku = function() {
|
101
|
+
this.getHighlightedSku = function () {
|
101
102
|
let rv = this.sku;
|
102
103
|
if (this.highlightedSku) rv = this.highlightedSku;
|
103
104
|
return rv;
|
104
105
|
};
|
105
106
|
|
106
|
-
this.getProductSearchTitle = function() {
|
107
|
+
this.getProductSearchTitle = function () {
|
107
108
|
if (this.agelocme && this.agelocme.label) {
|
108
109
|
return this.agelocme.label;
|
109
110
|
}
|
110
111
|
return this.title;
|
111
112
|
};
|
112
113
|
|
113
|
-
this.getProductSearchSku = function() {
|
114
|
+
this.getProductSearchSku = function () {
|
114
115
|
if (this.agelocme && this.agelocme.code) {
|
115
116
|
return this.agelocme.code;
|
116
117
|
}
|
117
118
|
return this.getHighlightedSku();
|
118
119
|
};
|
119
120
|
|
120
|
-
this.getDescription = function() {
|
121
|
+
this.getDescription = function () {
|
121
122
|
let description = this.longDescr;
|
122
123
|
if (!description || description.length === 0) {
|
123
124
|
return this.shortDescr;
|
@@ -125,7 +126,7 @@ const Product = function(productData) {
|
|
125
126
|
return description;
|
126
127
|
};
|
127
128
|
|
128
|
-
this.setFullImage = function(fullImage) {
|
129
|
+
this.setFullImage = function (fullImage) {
|
129
130
|
if (fullImage) {
|
130
131
|
this.fullImage = fullImage.replace("http:", "https:");
|
131
132
|
} else {
|
@@ -133,19 +134,19 @@ const Product = function(productData) {
|
|
133
134
|
}
|
134
135
|
};
|
135
136
|
|
136
|
-
this.getFullImage = function() {
|
137
|
+
this.getFullImage = function () {
|
137
138
|
return this.fullImage ? this.fullImage.replace("http:", "https:") : "";
|
138
139
|
};
|
139
140
|
|
140
|
-
this.setProductCarouselImages = function(productCarouselImages) {
|
141
|
+
this.setProductCarouselImages = function (productCarouselImages) {
|
141
142
|
this.productCarouselImages = productCarouselImages;
|
142
143
|
};
|
143
144
|
|
144
|
-
this.getProductCarouselImages = function() {
|
145
|
+
this.getProductCarouselImages = function () {
|
145
146
|
return this.productCarouselImages;
|
146
147
|
};
|
147
148
|
|
148
|
-
this.setImageAltText = function(altText) {
|
149
|
+
this.setImageAltText = function (altText) {
|
149
150
|
if (altText) {
|
150
151
|
this.imageAltText = altText;
|
151
152
|
} else {
|
@@ -153,11 +154,11 @@ const Product = function(productData) {
|
|
153
154
|
}
|
154
155
|
};
|
155
156
|
|
156
|
-
this.getImageAltText = function() {
|
157
|
+
this.getImageAltText = function () {
|
157
158
|
return this.imageAltText || this.title;
|
158
159
|
};
|
159
160
|
|
160
|
-
this.setThumbnail = function(thumbnail) {
|
161
|
+
this.setThumbnail = function (thumbnail) {
|
161
162
|
if (thumbnail) {
|
162
163
|
this.thumbnail = thumbnail.replace("http:", "https:");
|
163
164
|
} else {
|
@@ -165,7 +166,7 @@ const Product = function(productData) {
|
|
165
166
|
}
|
166
167
|
};
|
167
168
|
|
168
|
-
this.setThumbnailFromSku = function(sku) {
|
169
|
+
this.setThumbnailFromSku = function (sku) {
|
169
170
|
// WARNING: Base URL will need to be handled in the client (call setBaseUrl)
|
170
171
|
// eslint-disable-next-line max-len
|
171
172
|
// this.thumbnail = `${RunConfigService.getBaseUrl()}/content/products/${ProductUtils.getTokenizedSku(sku)}/jcr:content/fullImage.img.100.100.png`;
|
@@ -175,43 +176,43 @@ const Product = function(productData) {
|
|
175
176
|
)}/jcr:content/fullImage.img.100.100.png`;
|
176
177
|
};
|
177
178
|
|
178
|
-
this.getThumbnail = function() {
|
179
|
+
this.getThumbnail = function () {
|
179
180
|
return this.thumbnail ? this.thumbnail.replace("http:", "https:") : "";
|
180
181
|
};
|
181
182
|
|
182
|
-
this.hasAvailableQuantity = function(qty = 1) {
|
183
|
+
this.hasAvailableQuantity = function (qty = 1) {
|
183
184
|
return Math.min(this.maxQuantity, this.availableQuantity) >= qty;
|
184
185
|
};
|
185
186
|
|
186
|
-
this.setPoints = function(points) {
|
187
|
+
this.setPoints = function (points) {
|
187
188
|
this.points = ensureFloatVal(points) || "";
|
188
189
|
};
|
189
190
|
|
190
|
-
this.getPointsFixed = function() {
|
191
|
+
this.getPointsFixed = function () {
|
191
192
|
return parseFloat(this.points).toFixed(2);
|
192
193
|
};
|
193
194
|
|
194
|
-
this.setCv = function(cv) {
|
195
|
+
this.setCv = function (cv) {
|
195
196
|
this.cv = ensureFloatVal(cv) || "";
|
196
197
|
};
|
197
198
|
|
198
|
-
this.getCvFixed = function() {
|
199
|
+
this.getCvFixed = function () {
|
199
200
|
return parseFloat(this.cv).toFixed(2);
|
200
201
|
};
|
201
202
|
|
202
|
-
this.setPv = function(pv) {
|
203
|
+
this.setPv = function (pv) {
|
203
204
|
this.pv = ensureFloatVal(pv) || "";
|
204
205
|
};
|
205
206
|
|
206
|
-
this.getPvFixed = function() {
|
207
|
+
this.getPvFixed = function () {
|
207
208
|
return parseFloat(this.pv || 0).toFixed(2);
|
208
209
|
};
|
209
210
|
|
210
|
-
this.setPrice = function(price) {
|
211
|
+
this.setPrice = function (price) {
|
211
212
|
this.price = ensureFloatVal(price, true);
|
212
213
|
};
|
213
214
|
|
214
|
-
this.setFormattedPrice = function(formattedPrice) {
|
215
|
+
this.setFormattedPrice = function (formattedPrice) {
|
215
216
|
this.formattedPrice = formattedPrice;
|
216
217
|
};
|
217
218
|
|
@@ -220,13 +221,13 @@ const Product = function(productData) {
|
|
220
221
|
* added to the cart the event pricing needs to be remembered if toggling between
|
221
222
|
* pricetypes with event pricing and pricetype without event pricing
|
222
223
|
*/
|
223
|
-
this.lockEventName = function() {
|
224
|
+
this.lockEventName = function () {
|
224
225
|
if (!this.savedEventName && this.eventName) {
|
225
226
|
this.savedEventName = this.eventName;
|
226
227
|
}
|
227
228
|
};
|
228
229
|
|
229
|
-
this.setPriceAndPvFromType = function(_priceType, _activeEvents = null, option = {}) {
|
230
|
+
this.setPriceAndPvFromType = function (_priceType, _activeEvents = null, option = {}) {
|
230
231
|
// WARNING: priceType needs to be handled client-side
|
231
232
|
// const priceType = ConfigService.getMarketConfig().showWholeSalePricing && !AccountManager.isLoggedIn()
|
232
233
|
// ? PriceType.WWHL
|
@@ -271,11 +272,11 @@ const Product = function(productData) {
|
|
271
272
|
return changed;
|
272
273
|
};
|
273
274
|
|
274
|
-
this.getPrice = function() {
|
275
|
+
this.getPrice = function () {
|
275
276
|
return this.price ? this.price : 0;
|
276
277
|
};
|
277
278
|
|
278
|
-
this.getPriceFixed = function() {
|
279
|
+
this.getPriceFixed = function () {
|
279
280
|
if (typeof this.price === "number") {
|
280
281
|
return parseFloat(this.price.toFixed(2));
|
281
282
|
} else {
|
@@ -283,15 +284,15 @@ const Product = function(productData) {
|
|
283
284
|
}
|
284
285
|
};
|
285
286
|
|
286
|
-
this.getOriginalPrice = function() {
|
287
|
+
this.getOriginalPrice = function () {
|
287
288
|
return this.priceType ? this.priceMap[this.priceType] : null;
|
288
289
|
};
|
289
290
|
|
290
|
-
this.addPricing = function(type, price) {
|
291
|
+
this.addPricing = function (type, price) {
|
291
292
|
this.priceMap[type] = price;
|
292
293
|
};
|
293
294
|
|
294
|
-
this.addPricingFromStatus = function(productStatus, priceType, option ={}) {
|
295
|
+
this.addPricingFromStatus = function (productStatus, priceType, option = {}) {
|
295
296
|
let modified = false;
|
296
297
|
|
297
298
|
if (!priceType) {
|
@@ -326,7 +327,7 @@ const Product = function(productData) {
|
|
326
327
|
}, this);
|
327
328
|
}
|
328
329
|
this.orderTypes = ProductUtils.mergeOrderTypes(this.orderTypes, productStatus.orderType);
|
329
|
-
if(productStatus.childSkus) {
|
330
|
+
if (productStatus.childSkus) {
|
330
331
|
this.childSkus = productStatus.childSkus;
|
331
332
|
}
|
332
333
|
this.setPriceAndPvFromType(priceType, null, option);
|
@@ -346,15 +347,15 @@ const Product = function(productData) {
|
|
346
347
|
return modified;
|
347
348
|
};
|
348
349
|
|
349
|
-
this.addPvWithType = function(type, pv) {
|
350
|
+
this.addPvWithType = function (type, pv) {
|
350
351
|
this.pvMap[type] = pv;
|
351
352
|
};
|
352
353
|
|
353
|
-
this.addCvWithType = function(type, cv) {
|
354
|
+
this.addCvWithType = function (type, cv) {
|
354
355
|
this.cvMap[type] = cv;
|
355
356
|
};
|
356
357
|
|
357
|
-
this.getPricing = function(type) {
|
358
|
+
this.getPricing = function (type) {
|
358
359
|
let retVal = null;
|
359
360
|
|
360
361
|
if (type) {
|
@@ -381,7 +382,7 @@ const Product = function(productData) {
|
|
381
382
|
return eventPriceTypes;
|
382
383
|
};
|
383
384
|
|
384
|
-
this.getPvWithType = function(type) {
|
385
|
+
this.getPvWithType = function (type) {
|
385
386
|
let rv = this.pvMap[type];
|
386
387
|
if (rv == null) {
|
387
388
|
// Assumption: we always have WWHL from the service
|
@@ -391,7 +392,7 @@ const Product = function(productData) {
|
|
391
392
|
return rv;
|
392
393
|
};
|
393
394
|
|
394
|
-
this.getCvWithType = function(type) {
|
395
|
+
this.getCvWithType = function (type) {
|
395
396
|
let rv = this.cvMap[type];
|
396
397
|
if (rv == null) {
|
397
398
|
rv = this.cvMap[PriceType.WWHL];
|
@@ -399,77 +400,77 @@ const Product = function(productData) {
|
|
399
400
|
return rv;
|
400
401
|
};
|
401
402
|
|
402
|
-
this.hasAdrOption = function() {
|
403
|
+
this.hasAdrOption = function () {
|
403
404
|
return this.orderTypes["adr"];
|
404
405
|
};
|
405
406
|
|
406
|
-
this.isAdrOnly = function() {
|
407
|
+
this.isAdrOnly = function () {
|
407
408
|
return this.hasAdrOption() && !this.hasOrderOption();
|
408
409
|
};
|
409
410
|
|
410
|
-
this.hasMultipleOrderTypes = function() {
|
411
|
+
this.hasMultipleOrderTypes = function () {
|
411
412
|
return this.hasOrderOption() && this.hasAdrOption();
|
412
413
|
};
|
413
414
|
|
414
|
-
this.hasOrderOption = function() {
|
415
|
+
this.hasOrderOption = function () {
|
415
416
|
return this.orderTypes["order"];
|
416
417
|
};
|
417
418
|
|
418
|
-
this.isDistributor = function() {
|
419
|
+
this.isDistributor = function () {
|
419
420
|
return this.custTypes.includes("10");
|
420
421
|
};
|
421
422
|
|
422
|
-
this.isCustomer = function() {
|
423
|
+
this.isCustomer = function () {
|
423
424
|
return this.custTypes.includes("20");
|
424
425
|
};
|
425
426
|
|
426
|
-
this.isPreferredCustomer = function() {
|
427
|
+
this.isPreferredCustomer = function () {
|
427
428
|
return this.custTypes.includes("30");
|
428
429
|
};
|
429
430
|
|
430
|
-
this.isBase = function() {
|
431
|
+
this.isBase = function () {
|
431
432
|
return this.sku.substring(2, 4) === "55";
|
432
433
|
};
|
433
434
|
|
434
|
-
this.isVariant = function() {
|
435
|
+
this.isVariant = function () {
|
435
436
|
return this.baseSku.length > 0 && this.variantSkus().length === 0;
|
436
437
|
};
|
437
438
|
|
438
|
-
this.setVariant = function(variantProduct) {
|
439
|
+
this.setVariant = function (variantProduct) {
|
439
440
|
if (variantProduct && variantProduct.sku) {
|
440
441
|
this.variants[variantProduct.sku] = variantProduct;
|
441
442
|
}
|
442
443
|
};
|
443
444
|
|
444
|
-
this.getVariant = function(sku) {
|
445
|
+
this.getVariant = function (sku) {
|
445
446
|
return this.variants[sku];
|
446
447
|
};
|
447
448
|
|
448
|
-
this.variantSkus = function() {
|
449
|
+
this.variantSkus = function () {
|
449
450
|
return Object.keys(this.variants);
|
450
451
|
};
|
451
452
|
|
452
|
-
this.getVariantsList = function() {
|
453
|
+
this.getVariantsList = function () {
|
453
454
|
return Object.values(this.variants);
|
454
455
|
};
|
455
456
|
|
456
|
-
this.getMinPrice = function() {
|
457
|
+
this.getMinPrice = function () {
|
457
458
|
return this.priceMap[`min-${this.priceType}`];
|
458
459
|
};
|
459
460
|
|
460
|
-
this.getMaxPrice = function() {
|
461
|
+
this.getMaxPrice = function () {
|
461
462
|
return this.priceMap[`max-${this.priceType}`];
|
462
463
|
};
|
463
464
|
|
464
|
-
this.getMinPv = function() {
|
465
|
+
this.getMinPv = function () {
|
465
466
|
return this.pvMap[`min-${this.priceType}`];
|
466
467
|
};
|
467
468
|
|
468
|
-
this.getMaxPv = function() {
|
469
|
+
this.getMaxPv = function () {
|
469
470
|
return this.pvMap[`max-${this.priceType}`];
|
470
471
|
};
|
471
472
|
|
472
|
-
this.toJSON = function() {
|
473
|
+
this.toJSON = function () {
|
473
474
|
let retData = {};
|
474
475
|
retData.sku = this.sku;
|
475
476
|
retData.globalProductID = this.globalProductID;
|
@@ -534,15 +535,16 @@ const Product = function(productData) {
|
|
534
535
|
retData.addOns = this.addOns;
|
535
536
|
retData.inventory = this.inventory;
|
536
537
|
retData.equinoxProductId = this.equinoxProductId;
|
538
|
+
retData.properties = this.properties;
|
537
539
|
|
538
540
|
return retData;
|
539
541
|
};
|
540
542
|
|
541
|
-
this.setMeCommerceProductData = function(/*productData*/) {
|
543
|
+
this.setMeCommerceProductData = function (/*productData*/) {
|
542
544
|
console.error("setMeCommerceProductData is deprecated!");
|
543
545
|
};
|
544
546
|
|
545
|
-
this.setBaseUrl = function(baseUrl) {
|
547
|
+
this.setBaseUrl = function (baseUrl) {
|
546
548
|
this.thumbnail = ProductUtils.applyBaseUrl(this.thumbnail, baseUrl);
|
547
549
|
this.fullImage = ProductUtils.applyBaseUrl(this.fullImage, baseUrl);
|
548
550
|
|
@@ -554,7 +556,7 @@ const Product = function(productData) {
|
|
554
556
|
}
|
555
557
|
};
|
556
558
|
|
557
|
-
this.setProductData = function(productData) {
|
559
|
+
this.setProductData = function (productData) {
|
558
560
|
let data;
|
559
561
|
|
560
562
|
if (productData) {
|
@@ -662,7 +664,7 @@ const Product = function(productData) {
|
|
662
664
|
? data.pvMap
|
663
665
|
: this.pvMap;
|
664
666
|
this.orderTypes = ProductUtils.mergeOrderTypes(this.orderTypes, data.orderTypes);
|
665
|
-
if(data.childSkus) {
|
667
|
+
if (data.childSkus) {
|
666
668
|
this.childSkus = data.childSkus;
|
667
669
|
}
|
668
670
|
this.custTypes = data.custTypes || [];
|
@@ -675,10 +677,11 @@ const Product = function(productData) {
|
|
675
677
|
}
|
676
678
|
|
677
679
|
this.equinoxProductId = data.equinoxProductId;
|
680
|
+
this.properties = data.properties;
|
678
681
|
}
|
679
682
|
};
|
680
683
|
|
681
|
-
this.isEmpty = function() {
|
684
|
+
this.isEmpty = function () {
|
682
685
|
return (
|
683
686
|
isFieldEmpty(this.sku) &&
|
684
687
|
isFieldEmpty(this.title) &&
|