@nuskin/ns-product-lib 2.5.0-fix.2 → 2.5.1-cx24-3282m.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +210 -0
- package/package.json +2 -1
- package/src/contentstack/contentstack.js +3 -101
- package/src/index.js +5 -3
- package/src/models/customerTypes.js +16 -0
- package/src/{productStatus.js → models/productStatus.js} +7 -0
- package/src/product.js +85 -70
- package/src/productData.js +307 -95
- /package/src/{priceType.js → models/priceType.js} +0 -0
package/src/product.js
CHANGED
@@ -1,14 +1,14 @@
|
|
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
|
|
7
7
|
const Agelocme = require("./agelocme.js");
|
8
|
-
const PriceType = require("./priceType.js");
|
9
|
-
const ProductStatus = require("./productStatus.js");
|
8
|
+
const PriceType = require("./models/priceType.js");
|
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 = {};
|
@@ -75,14 +75,15 @@ const Product = function(productData) {
|
|
75
75
|
//equinox inventory / stock label
|
76
76
|
//@example "IN STOCK"
|
77
77
|
this.inventory = "";
|
78
|
+
this.equinoxProductId = "";
|
78
79
|
|
79
|
-
this.setMarketAttributes = function(productStatus) {
|
80
|
+
this.setMarketAttributes = function (productStatus) {
|
80
81
|
if (productStatus.marketAttributes) {
|
81
82
|
this.marketAttributes = productStatus.marketAttributes;
|
82
83
|
}
|
83
84
|
};
|
84
85
|
|
85
|
-
this.getAgelocmeKeyPart = function() {
|
86
|
+
this.getAgelocmeKeyPart = function () {
|
86
87
|
let keyPart = null;
|
87
88
|
if (this.agelocme) {
|
88
89
|
keyPart =
|
@@ -96,27 +97,27 @@ const Product = function(productData) {
|
|
96
97
|
return keyPart;
|
97
98
|
};
|
98
99
|
|
99
|
-
this.getHighlightedSku = function() {
|
100
|
+
this.getHighlightedSku = function () {
|
100
101
|
let rv = this.sku;
|
101
102
|
if (this.highlightedSku) rv = this.highlightedSku;
|
102
103
|
return rv;
|
103
104
|
};
|
104
105
|
|
105
|
-
this.getProductSearchTitle = function() {
|
106
|
+
this.getProductSearchTitle = function () {
|
106
107
|
if (this.agelocme && this.agelocme.label) {
|
107
108
|
return this.agelocme.label;
|
108
109
|
}
|
109
110
|
return this.title;
|
110
111
|
};
|
111
112
|
|
112
|
-
this.getProductSearchSku = function() {
|
113
|
+
this.getProductSearchSku = function () {
|
113
114
|
if (this.agelocme && this.agelocme.code) {
|
114
115
|
return this.agelocme.code;
|
115
116
|
}
|
116
117
|
return this.getHighlightedSku();
|
117
118
|
};
|
118
119
|
|
119
|
-
this.getDescription = function() {
|
120
|
+
this.getDescription = function () {
|
120
121
|
let description = this.longDescr;
|
121
122
|
if (!description || description.length === 0) {
|
122
123
|
return this.shortDescr;
|
@@ -124,7 +125,7 @@ const Product = function(productData) {
|
|
124
125
|
return description;
|
125
126
|
};
|
126
127
|
|
127
|
-
this.setFullImage = function(fullImage) {
|
128
|
+
this.setFullImage = function (fullImage) {
|
128
129
|
if (fullImage) {
|
129
130
|
this.fullImage = fullImage.replace("http:", "https:");
|
130
131
|
} else {
|
@@ -132,19 +133,19 @@ const Product = function(productData) {
|
|
132
133
|
}
|
133
134
|
};
|
134
135
|
|
135
|
-
this.getFullImage = function() {
|
136
|
+
this.getFullImage = function () {
|
136
137
|
return this.fullImage ? this.fullImage.replace("http:", "https:") : "";
|
137
138
|
};
|
138
139
|
|
139
|
-
this.setProductCarouselImages = function(productCarouselImages) {
|
140
|
+
this.setProductCarouselImages = function (productCarouselImages) {
|
140
141
|
this.productCarouselImages = productCarouselImages;
|
141
142
|
};
|
142
143
|
|
143
|
-
this.getProductCarouselImages = function() {
|
144
|
+
this.getProductCarouselImages = function () {
|
144
145
|
return this.productCarouselImages;
|
145
146
|
};
|
146
147
|
|
147
|
-
this.setImageAltText = function(altText) {
|
148
|
+
this.setImageAltText = function (altText) {
|
148
149
|
if (altText) {
|
149
150
|
this.imageAltText = altText;
|
150
151
|
} else {
|
@@ -152,11 +153,11 @@ const Product = function(productData) {
|
|
152
153
|
}
|
153
154
|
};
|
154
155
|
|
155
|
-
this.getImageAltText = function() {
|
156
|
+
this.getImageAltText = function () {
|
156
157
|
return this.imageAltText || this.title;
|
157
158
|
};
|
158
159
|
|
159
|
-
this.setThumbnail = function(thumbnail) {
|
160
|
+
this.setThumbnail = function (thumbnail) {
|
160
161
|
if (thumbnail) {
|
161
162
|
this.thumbnail = thumbnail.replace("http:", "https:");
|
162
163
|
} else {
|
@@ -164,7 +165,7 @@ const Product = function(productData) {
|
|
164
165
|
}
|
165
166
|
};
|
166
167
|
|
167
|
-
this.setThumbnailFromSku = function(sku) {
|
168
|
+
this.setThumbnailFromSku = function (sku) {
|
168
169
|
// WARNING: Base URL will need to be handled in the client (call setBaseUrl)
|
169
170
|
// eslint-disable-next-line max-len
|
170
171
|
// this.thumbnail = `${RunConfigService.getBaseUrl()}/content/products/${ProductUtils.getTokenizedSku(sku)}/jcr:content/fullImage.img.100.100.png`;
|
@@ -174,43 +175,43 @@ const Product = function(productData) {
|
|
174
175
|
)}/jcr:content/fullImage.img.100.100.png`;
|
175
176
|
};
|
176
177
|
|
177
|
-
this.getThumbnail = function() {
|
178
|
+
this.getThumbnail = function () {
|
178
179
|
return this.thumbnail ? this.thumbnail.replace("http:", "https:") : "";
|
179
180
|
};
|
180
181
|
|
181
|
-
this.hasAvailableQuantity = function(qty = 1) {
|
182
|
+
this.hasAvailableQuantity = function (qty = 1) {
|
182
183
|
return Math.min(this.maxQuantity, this.availableQuantity) >= qty;
|
183
184
|
};
|
184
185
|
|
185
|
-
this.setPoints = function(points) {
|
186
|
+
this.setPoints = function (points) {
|
186
187
|
this.points = ensureFloatVal(points) || "";
|
187
188
|
};
|
188
189
|
|
189
|
-
this.getPointsFixed = function() {
|
190
|
+
this.getPointsFixed = function () {
|
190
191
|
return parseFloat(this.points).toFixed(2);
|
191
192
|
};
|
192
193
|
|
193
|
-
this.setCv = function(cv) {
|
194
|
+
this.setCv = function (cv) {
|
194
195
|
this.cv = ensureFloatVal(cv) || "";
|
195
196
|
};
|
196
197
|
|
197
|
-
this.getCvFixed = function() {
|
198
|
+
this.getCvFixed = function () {
|
198
199
|
return parseFloat(this.cv).toFixed(2);
|
199
200
|
};
|
200
201
|
|
201
|
-
this.setPv = function(pv) {
|
202
|
+
this.setPv = function (pv) {
|
202
203
|
this.pv = ensureFloatVal(pv) || "";
|
203
204
|
};
|
204
205
|
|
205
|
-
this.getPvFixed = function() {
|
206
|
+
this.getPvFixed = function () {
|
206
207
|
return parseFloat(this.pv || 0).toFixed(2);
|
207
208
|
};
|
208
209
|
|
209
|
-
this.setPrice = function(price) {
|
210
|
+
this.setPrice = function (price) {
|
210
211
|
this.price = ensureFloatVal(price, true);
|
211
212
|
};
|
212
213
|
|
213
|
-
this.setFormattedPrice = function(formattedPrice) {
|
214
|
+
this.setFormattedPrice = function (formattedPrice) {
|
214
215
|
this.formattedPrice = formattedPrice;
|
215
216
|
};
|
216
217
|
|
@@ -219,13 +220,13 @@ const Product = function(productData) {
|
|
219
220
|
* added to the cart the event pricing needs to be remembered if toggling between
|
220
221
|
* pricetypes with event pricing and pricetype without event pricing
|
221
222
|
*/
|
222
|
-
this.lockEventName = function() {
|
223
|
+
this.lockEventName = function () {
|
223
224
|
if (!this.savedEventName && this.eventName) {
|
224
225
|
this.savedEventName = this.eventName;
|
225
226
|
}
|
226
227
|
};
|
227
228
|
|
228
|
-
this.setPriceAndPvFromType = function(_priceType, _activeEvents = null) {
|
229
|
+
this.setPriceAndPvFromType = function (_priceType, _activeEvents = null, option = {}) {
|
229
230
|
// WARNING: priceType needs to be handled client-side
|
230
231
|
// const priceType = ConfigService.getMarketConfig().showWholeSalePricing && !AccountManager.isLoggedIn()
|
231
232
|
// ? PriceType.WWHL
|
@@ -234,11 +235,11 @@ const Product = function(productData) {
|
|
234
235
|
const eventPricing = getEventPricing(this, priceType, _activeEvents);
|
235
236
|
|
236
237
|
let changed = false;
|
237
|
-
if (
|
238
|
+
if ((
|
238
239
|
!this.price ||
|
239
240
|
priceType !== this.priceType ||
|
240
241
|
this.eventName !== eventPricing.eventName
|
241
|
-
) {
|
242
|
+
) && !option.isEqPromotion) {
|
242
243
|
this.setPrice(eventPricing.price || this.getPricing(priceType));
|
243
244
|
this.setCv(eventPricing.cv || this.getCvWithType(priceType));
|
244
245
|
this.setPv(eventPricing.pv || this.getPvWithType(priceType));
|
@@ -247,11 +248,20 @@ const Product = function(productData) {
|
|
247
248
|
changed = true;
|
248
249
|
}
|
249
250
|
|
251
|
+
if (option.isEqPromotion) {
|
252
|
+
//retain product.price as original price
|
253
|
+
this.setCv(this.getCvWithType(priceType));
|
254
|
+
this.setPv(this.getPvWithType(priceType));
|
255
|
+
this.priceType = priceType;
|
256
|
+
changed = true;
|
257
|
+
}
|
258
|
+
|
250
259
|
this.variantSkus().forEach((variantSku) => {
|
251
260
|
if (
|
252
261
|
this.variants[variantSku].setPriceAndPvFromType(
|
253
262
|
priceType,
|
254
|
-
_activeEvents
|
263
|
+
_activeEvents,
|
264
|
+
option
|
255
265
|
)
|
256
266
|
) {
|
257
267
|
changed = true;
|
@@ -261,11 +271,11 @@ const Product = function(productData) {
|
|
261
271
|
return changed;
|
262
272
|
};
|
263
273
|
|
264
|
-
this.getPrice = function() {
|
274
|
+
this.getPrice = function () {
|
265
275
|
return this.price ? this.price : 0;
|
266
276
|
};
|
267
277
|
|
268
|
-
this.getPriceFixed = function() {
|
278
|
+
this.getPriceFixed = function () {
|
269
279
|
if (typeof this.price === "number") {
|
270
280
|
return parseFloat(this.price.toFixed(2));
|
271
281
|
} else {
|
@@ -273,15 +283,15 @@ const Product = function(productData) {
|
|
273
283
|
}
|
274
284
|
};
|
275
285
|
|
276
|
-
this.getOriginalPrice = function() {
|
286
|
+
this.getOriginalPrice = function () {
|
277
287
|
return this.priceType ? this.priceMap[this.priceType] : null;
|
278
288
|
};
|
279
289
|
|
280
|
-
this.addPricing = function(type, price) {
|
290
|
+
this.addPricing = function (type, price) {
|
281
291
|
this.priceMap[type] = price;
|
282
292
|
};
|
283
293
|
|
284
|
-
this.addPricingFromStatus = function(productStatus, priceType) {
|
294
|
+
this.addPricingFromStatus = function (productStatus, priceType, option = {}) {
|
285
295
|
let modified = false;
|
286
296
|
|
287
297
|
if (!priceType) {
|
@@ -293,7 +303,9 @@ const Product = function(productData) {
|
|
293
303
|
if (productStatusSku === this.sku) {
|
294
304
|
this.globalProductID = productStatus.globalProductID;
|
295
305
|
this.status = productStatus.status;
|
296
|
-
|
306
|
+
if (!option.isEqPromotion) {
|
307
|
+
this.availableQuantity = productStatus.availableQuantity;
|
308
|
+
}
|
297
309
|
this.maxQuantity = productStatus.maxQuantity || 999;
|
298
310
|
this.locallyProduced = productStatus.locallyProduced || false;
|
299
311
|
if (productStatus.backordered) {
|
@@ -316,16 +328,16 @@ const Product = function(productData) {
|
|
316
328
|
}, this);
|
317
329
|
}
|
318
330
|
this.orderTypes = ProductUtils.mergeOrderTypes(this.orderTypes, productStatus.orderType);
|
319
|
-
if(productStatus.childSkus) {
|
331
|
+
if (productStatus.childSkus) {
|
320
332
|
this.childSkus = productStatus.childSkus;
|
321
333
|
}
|
322
|
-
this.setPriceAndPvFromType(priceType);
|
334
|
+
this.setPriceAndPvFromType(priceType, null, option);
|
323
335
|
modified = true;
|
324
336
|
} else {
|
325
337
|
let variant = this.getVariant(productStatusSku);
|
326
338
|
|
327
339
|
if (variant) {
|
328
|
-
if (variant.addPricingFromStatus(productStatus, priceType)) {
|
340
|
+
if (variant.addPricingFromStatus(productStatus, priceType, option)) {
|
329
341
|
variant.setMarketAttributes(productStatus);
|
330
342
|
updateBaseRanges(this, variant);
|
331
343
|
modified = true;
|
@@ -336,15 +348,15 @@ const Product = function(productData) {
|
|
336
348
|
return modified;
|
337
349
|
};
|
338
350
|
|
339
|
-
this.addPvWithType = function(type, pv) {
|
351
|
+
this.addPvWithType = function (type, pv) {
|
340
352
|
this.pvMap[type] = pv;
|
341
353
|
};
|
342
354
|
|
343
|
-
this.addCvWithType = function(type, cv) {
|
355
|
+
this.addCvWithType = function (type, cv) {
|
344
356
|
this.cvMap[type] = cv;
|
345
357
|
};
|
346
358
|
|
347
|
-
this.getPricing = function(type) {
|
359
|
+
this.getPricing = function (type) {
|
348
360
|
let retVal = null;
|
349
361
|
|
350
362
|
if (type) {
|
@@ -371,7 +383,7 @@ const Product = function(productData) {
|
|
371
383
|
return eventPriceTypes;
|
372
384
|
};
|
373
385
|
|
374
|
-
this.getPvWithType = function(type) {
|
386
|
+
this.getPvWithType = function (type) {
|
375
387
|
let rv = this.pvMap[type];
|
376
388
|
if (rv == null) {
|
377
389
|
// Assumption: we always have WWHL from the service
|
@@ -381,7 +393,7 @@ const Product = function(productData) {
|
|
381
393
|
return rv;
|
382
394
|
};
|
383
395
|
|
384
|
-
this.getCvWithType = function(type) {
|
396
|
+
this.getCvWithType = function (type) {
|
385
397
|
let rv = this.cvMap[type];
|
386
398
|
if (rv == null) {
|
387
399
|
rv = this.cvMap[PriceType.WWHL];
|
@@ -389,77 +401,77 @@ const Product = function(productData) {
|
|
389
401
|
return rv;
|
390
402
|
};
|
391
403
|
|
392
|
-
this.hasAdrOption = function() {
|
404
|
+
this.hasAdrOption = function () {
|
393
405
|
return this.orderTypes["adr"];
|
394
406
|
};
|
395
407
|
|
396
|
-
this.isAdrOnly = function() {
|
408
|
+
this.isAdrOnly = function () {
|
397
409
|
return this.hasAdrOption() && !this.hasOrderOption();
|
398
410
|
};
|
399
411
|
|
400
|
-
this.hasMultipleOrderTypes = function() {
|
412
|
+
this.hasMultipleOrderTypes = function () {
|
401
413
|
return this.hasOrderOption() && this.hasAdrOption();
|
402
414
|
};
|
403
415
|
|
404
|
-
this.hasOrderOption = function() {
|
416
|
+
this.hasOrderOption = function () {
|
405
417
|
return this.orderTypes["order"];
|
406
418
|
};
|
407
419
|
|
408
|
-
this.isDistributor = function() {
|
420
|
+
this.isDistributor = function () {
|
409
421
|
return this.custTypes.includes("10");
|
410
422
|
};
|
411
423
|
|
412
|
-
this.isCustomer = function() {
|
424
|
+
this.isCustomer = function () {
|
413
425
|
return this.custTypes.includes("20");
|
414
426
|
};
|
415
427
|
|
416
|
-
this.isPreferredCustomer = function() {
|
428
|
+
this.isPreferredCustomer = function () {
|
417
429
|
return this.custTypes.includes("30");
|
418
430
|
};
|
419
431
|
|
420
|
-
this.isBase = function() {
|
432
|
+
this.isBase = function () {
|
421
433
|
return this.sku.substring(2, 4) === "55";
|
422
434
|
};
|
423
435
|
|
424
|
-
this.isVariant = function() {
|
436
|
+
this.isVariant = function () {
|
425
437
|
return this.baseSku.length > 0 && this.variantSkus().length === 0;
|
426
438
|
};
|
427
439
|
|
428
|
-
this.setVariant = function(variantProduct) {
|
440
|
+
this.setVariant = function (variantProduct) {
|
429
441
|
if (variantProduct && variantProduct.sku) {
|
430
442
|
this.variants[variantProduct.sku] = variantProduct;
|
431
443
|
}
|
432
444
|
};
|
433
445
|
|
434
|
-
this.getVariant = function(sku) {
|
446
|
+
this.getVariant = function (sku) {
|
435
447
|
return this.variants[sku];
|
436
448
|
};
|
437
449
|
|
438
|
-
this.variantSkus = function() {
|
450
|
+
this.variantSkus = function () {
|
439
451
|
return Object.keys(this.variants);
|
440
452
|
};
|
441
453
|
|
442
|
-
this.getVariantsList = function() {
|
454
|
+
this.getVariantsList = function () {
|
443
455
|
return Object.values(this.variants);
|
444
456
|
};
|
445
457
|
|
446
|
-
this.getMinPrice = function() {
|
458
|
+
this.getMinPrice = function () {
|
447
459
|
return this.priceMap[`min-${this.priceType}`];
|
448
460
|
};
|
449
461
|
|
450
|
-
this.getMaxPrice = function() {
|
462
|
+
this.getMaxPrice = function () {
|
451
463
|
return this.priceMap[`max-${this.priceType}`];
|
452
464
|
};
|
453
465
|
|
454
|
-
this.getMinPv = function() {
|
466
|
+
this.getMinPv = function () {
|
455
467
|
return this.pvMap[`min-${this.priceType}`];
|
456
468
|
};
|
457
469
|
|
458
|
-
this.getMaxPv = function() {
|
470
|
+
this.getMaxPv = function () {
|
459
471
|
return this.pvMap[`max-${this.priceType}`];
|
460
472
|
};
|
461
473
|
|
462
|
-
this.toJSON = function() {
|
474
|
+
this.toJSON = function () {
|
463
475
|
let retData = {};
|
464
476
|
retData.sku = this.sku;
|
465
477
|
retData.globalProductID = this.globalProductID;
|
@@ -523,15 +535,16 @@ const Product = function(productData) {
|
|
523
535
|
retData.restrictedMarkets = this.restrictedMarkets;
|
524
536
|
retData.addOns = this.addOns;
|
525
537
|
retData.inventory = this.inventory;
|
538
|
+
retData.equinoxProductId = this.equinoxProductId;
|
526
539
|
|
527
540
|
return retData;
|
528
541
|
};
|
529
542
|
|
530
|
-
this.setMeCommerceProductData = function(/*productData*/) {
|
543
|
+
this.setMeCommerceProductData = function (/*productData*/) {
|
531
544
|
console.error("setMeCommerceProductData is deprecated!");
|
532
545
|
};
|
533
546
|
|
534
|
-
this.setBaseUrl = function(baseUrl) {
|
547
|
+
this.setBaseUrl = function (baseUrl) {
|
535
548
|
this.thumbnail = ProductUtils.applyBaseUrl(this.thumbnail, baseUrl);
|
536
549
|
this.fullImage = ProductUtils.applyBaseUrl(this.fullImage, baseUrl);
|
537
550
|
|
@@ -543,7 +556,7 @@ const Product = function(productData) {
|
|
543
556
|
}
|
544
557
|
};
|
545
558
|
|
546
|
-
this.setProductData = function(productData) {
|
559
|
+
this.setProductData = function (productData) {
|
547
560
|
let data;
|
548
561
|
|
549
562
|
if (productData) {
|
@@ -651,7 +664,7 @@ const Product = function(productData) {
|
|
651
664
|
? data.pvMap
|
652
665
|
: this.pvMap;
|
653
666
|
this.orderTypes = ProductUtils.mergeOrderTypes(this.orderTypes, data.orderTypes);
|
654
|
-
if(data.childSkus) {
|
667
|
+
if (data.childSkus) {
|
655
668
|
this.childSkus = data.childSkus;
|
656
669
|
}
|
657
670
|
this.custTypes = data.custTypes || [];
|
@@ -662,10 +675,12 @@ const Product = function(productData) {
|
|
662
675
|
if (data.agelocme) {
|
663
676
|
this.agelocme = new Agelocme(data.agelocme);
|
664
677
|
}
|
678
|
+
|
679
|
+
this.equinoxProductId = data.equinoxProductId;
|
665
680
|
}
|
666
681
|
};
|
667
682
|
|
668
|
-
this.isEmpty = function() {
|
683
|
+
this.isEmpty = function () {
|
669
684
|
return (
|
670
685
|
isFieldEmpty(this.sku) &&
|
671
686
|
isFieldEmpty(this.title) &&
|