@nuskin/ns-product-lib 2.7.0-cx24-3682.12 → 2.7.0-cx24-3702.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +15 -60
- package/package.json +2 -2
- package/src/equinox-helpers/childSKU.js +1 -1
- package/src/equinox-helpers/index.js +31 -172
- package/src/product.js +65 -62
- package/src/productData.js +43 -27
- package/src/equinox-helpers/interceptors/index.js +0 -5
- package/src/equinox-helpers/interceptors/productNotFound.js +0 -70
- package/src/equinox-helpers/mappers/identifier.js +0 -13
- package/src/equinox-helpers/mappers/index.js +0 -11
- package/src/equinox-helpers/mappers/inventoryProperties.js +0 -173
- package/src/equinox-helpers/mappers/properties.js +0 -182
- package/src/equinox-helpers/mappers/variant.js +0 -71
- package/src/equinox-helpers/models/index.js +0 -5
- package/src/equinox-helpers/models/productNotFound.js +0 -54
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) &&
|
package/src/productData.js
CHANGED
@@ -6,7 +6,6 @@ const Product = require("./product");
|
|
6
6
|
const CustomerTypes = require('./models/customerTypes');
|
7
7
|
const ProductStatus = require("./models/productStatus");
|
8
8
|
const { mapAvailableQuantity, mapChildSKU } = require('./equinox-helpers');
|
9
|
-
const { productNotFoundInterceptor } = require('./equinox-helpers/interceptors');
|
10
9
|
|
11
10
|
const productTypes = {
|
12
11
|
kit: 'kit'
|
@@ -67,11 +66,9 @@ const ProductData = {
|
|
67
66
|
}
|
68
67
|
|
69
68
|
const filter = skuFilter.join(" OR ")
|
70
|
-
//axios.defaults.withCredentials = true;
|
71
69
|
|
72
70
|
const url = `${config.API_Base_URLs}/orchestrationservices/storefront/catalogs/search/`;
|
73
71
|
const href = `${url}?filter='\\\\''${encodeURI(filter)}'\\''`;
|
74
|
-
axios.interceptors.response.use((res) => res, productNotFoundInterceptor);
|
75
72
|
const response = await axios.request({
|
76
73
|
method: 'get',
|
77
74
|
url: href,
|
@@ -84,7 +81,6 @@ const ProductData = {
|
|
84
81
|
withCredentials: true
|
85
82
|
});
|
86
83
|
|
87
|
-
axios.interceptors.response.eject(productNotFoundInterceptor);
|
88
84
|
return response;
|
89
85
|
},
|
90
86
|
|
@@ -136,9 +132,11 @@ const ProductData = {
|
|
136
132
|
let thumbnailImage = imageURL ? imageURL + '?width=40' : ''
|
137
133
|
|
138
134
|
|
139
|
-
const { eventName, eventLabels, computedPrice, defaultProductPrice } = this.getEqProductPromotions(eqVariant);
|
135
|
+
const { eventName, eventLabels, computedPrice, defaultProductPrice, CVPrice, PVPrice } = this.getEqProductPromotions(eqVariant);
|
140
136
|
const productPrice = eventName ? defaultProductPrice : eqVariant.priceFacets["Regular Price"];
|
141
137
|
const discountedPrice = eventName ? computedPrice : eqVariant.priceFacets["Regular Price"];
|
138
|
+
const productCVPrice = eventName ? CVPrice : eqVariant.priceFacets.CV;
|
139
|
+
const productPVPrice = eventName ? PVPrice : eqVariant.priceFacets.PV;
|
142
140
|
|
143
141
|
return {
|
144
142
|
"sku": eqVariant.identifier,
|
@@ -245,8 +243,8 @@ const ProductData = {
|
|
245
243
|
"availableQuantity": eqVariant.inventoryProperties.atpQty,
|
246
244
|
"maxQuantity": 999,
|
247
245
|
"points": "",
|
248
|
-
"cv":
|
249
|
-
"pv":
|
246
|
+
"cv": productCVPrice,
|
247
|
+
"pv": productPVPrice,
|
250
248
|
"priceType": "WRTL",
|
251
249
|
"price": discountedPrice,
|
252
250
|
"priceMap": {
|
@@ -259,14 +257,14 @@ const ProductData = {
|
|
259
257
|
"WHL": eqVariant.priceFacets["Wholesale Price"]
|
260
258
|
},
|
261
259
|
"cvMap": {
|
262
|
-
"WWHL":
|
263
|
-
"WADW":
|
264
|
-
"WHL":
|
260
|
+
"WWHL": productCVPrice,
|
261
|
+
"WADW": productCVPrice,
|
262
|
+
"WHL": productCVPrice
|
265
263
|
},
|
266
264
|
"pvMap": {
|
267
|
-
"WWHL":
|
268
|
-
"WADW":
|
269
|
-
"WHL":
|
265
|
+
"WWHL": productPVPrice,
|
266
|
+
"WADW": productPVPrice,
|
267
|
+
"WHL": productPVPrice
|
270
268
|
},
|
271
269
|
"orderTypes": this._setOrderType(eqVariant.properties),
|
272
270
|
"custTypes": this.switchCustType(eqVariant.properties.customerTypes),
|
@@ -278,7 +276,7 @@ const ProductData = {
|
|
278
276
|
"flavor": "",
|
279
277
|
"size": eqVariant.properties.size,
|
280
278
|
"shade": "",
|
281
|
-
"status": this.switchStatusFromEquinox(eqVariant.properties.
|
279
|
+
"status": this.switchStatusFromEquinox(eqVariant.properties.productStatus),
|
282
280
|
"variantType": "Other",
|
283
281
|
"variantDropdownLabel": eqVariant.properties.variantLabel || "",
|
284
282
|
"variantDropdownPlaceholder": "Select Type",
|
@@ -299,7 +297,8 @@ const ProductData = {
|
|
299
297
|
},
|
300
298
|
"restrictedMarkets": [],
|
301
299
|
"addOns": [],
|
302
|
-
"equinoxProductId": eqVariant.identifier
|
300
|
+
"equinoxProductId": eqVariant.identifier,
|
301
|
+
"properties": eqVariant.properties
|
303
302
|
};
|
304
303
|
},
|
305
304
|
|
@@ -323,6 +322,16 @@ const ProductData = {
|
|
323
322
|
const computedPrice = product.totalValue && product.totalValue.priceAfterDiscount
|
324
323
|
? product.totalValue.priceAfterDiscount
|
325
324
|
: 0;
|
325
|
+
|
326
|
+
let CVPrice = 0,
|
327
|
+
PVPrice = 0;
|
328
|
+
|
329
|
+
if (product.totalValue && product.totalValue.priceFacets) {
|
330
|
+
const productPriceFacets = product.totalValue.priceFacets;
|
331
|
+
CVPrice = productPriceFacets.CV && productPriceFacets.CV.CVAfterDiscount ? productPriceFacets.CV.CVAfterDiscount : 0;
|
332
|
+
PVPrice = productPriceFacets.PV && productPriceFacets.PV.PVAfterDiscount ? productPriceFacets.PV.PVAfterDiscount : 0;
|
333
|
+
}
|
334
|
+
|
326
335
|
let eventName = "";
|
327
336
|
const eventLabels = [];
|
328
337
|
|
@@ -336,17 +345,19 @@ const ProductData = {
|
|
336
345
|
eventLabels: eventLabels.join(','),
|
337
346
|
defaultProductPrice,
|
338
347
|
computedPrice,
|
339
|
-
eventName
|
348
|
+
eventName,
|
349
|
+
CVPrice,
|
350
|
+
PVPrice
|
340
351
|
}
|
341
352
|
},
|
342
353
|
|
343
354
|
eqProductMapper: async function (productDataResponse, skus) {
|
344
355
|
let count = 0;
|
345
|
-
let variants = {};
|
346
356
|
const products = [];
|
347
357
|
|
348
358
|
for (const productData of productDataResponse) {
|
349
359
|
try {
|
360
|
+
let variants = {};
|
350
361
|
let product = (productData.type && productData.type === "kit") ? productData : productData.sku[count];
|
351
362
|
let imageURL = product.properties.imageURL ? product.properties.imageURL : '';
|
352
363
|
let thumbnailImage = imageURL ? imageURL + '?width=40' : ''
|
@@ -364,10 +375,14 @@ const ProductData = {
|
|
364
375
|
eventName,
|
365
376
|
eventLabels,
|
366
377
|
computedPrice,
|
367
|
-
defaultProductPrice
|
378
|
+
defaultProductPrice,
|
379
|
+
CVPrice,
|
380
|
+
PVPrice
|
368
381
|
} = this.getEqProductPromotions(product);
|
369
382
|
const productPrice = eventName ? defaultProductPrice : product.priceFacets["Regular Price"];
|
370
383
|
const discountedPrice = eventName ? computedPrice : product.priceFacets["Regular Price"];
|
384
|
+
const productCVPrice = eventName ? CVPrice : product.priceFacets.CV;
|
385
|
+
const productPVPrice = eventName ? PVPrice : product.priceFacets.PV;
|
371
386
|
|
372
387
|
product.childSkus = await this.fetchChildSkus(product);
|
373
388
|
product.availableQuantity = mapAvailableQuantity(product);
|
@@ -406,8 +421,8 @@ const ProductData = {
|
|
406
421
|
"scanQualified": productData.properties.scanQualifiedCount,
|
407
422
|
"maxQuantity": 999,
|
408
423
|
"points": "",
|
409
|
-
"cv":
|
410
|
-
"pv":
|
424
|
+
"cv": productCVPrice,
|
425
|
+
"pv": productPVPrice,
|
411
426
|
"priceType": "WRTL",
|
412
427
|
"price": discountedPrice,
|
413
428
|
"priceMap": {
|
@@ -420,14 +435,14 @@ const ProductData = {
|
|
420
435
|
"WWHL": product.priceFacets["Wholesale Price"]
|
421
436
|
},
|
422
437
|
"cvMap": {
|
423
|
-
"WWHL":
|
424
|
-
"WADW":
|
425
|
-
"WHL":
|
438
|
+
"WWHL": productCVPrice,
|
439
|
+
"WADW": productCVPrice,
|
440
|
+
"WHL": productCVPrice
|
426
441
|
},
|
427
442
|
"pvMap": {
|
428
|
-
"WWHL":
|
429
|
-
"WADW":
|
430
|
-
"WHL":
|
443
|
+
"WWHL": productPVPrice,
|
444
|
+
"WADW": productPVPrice,
|
445
|
+
"WHL": productPVPrice
|
431
446
|
},
|
432
447
|
"orderTypes": this._setOrderType(product.properties),
|
433
448
|
"custTypes": this.switchCustType(product.properties.customerTypes),
|
@@ -462,7 +477,8 @@ const ProductData = {
|
|
462
477
|
"restrictedMarkets": [],
|
463
478
|
"addOns": [],
|
464
479
|
"inventory": product.inventory || "", //inventory label
|
465
|
-
"equinoxProductId": productData.identifier
|
480
|
+
"equinoxProductId": productData.identifier,
|
481
|
+
"properties": product.properties
|
466
482
|
};
|
467
483
|
|
468
484
|
products.push(new Product(product));
|
@@ -1,70 +0,0 @@
|
|
1
|
-
const { productNotFound } = require('../models');
|
2
|
-
|
3
|
-
// httpStatus codes
|
4
|
-
const httpStatus = { notFound: 404 };
|
5
|
-
|
6
|
-
/**
|
7
|
-
* productNotFoundInterceptor returns a model "ProductNotFound" when the status code is Not Found.
|
8
|
-
* Note: Do not polute this file. Create a new file for new interceptor.
|
9
|
-
*
|
10
|
-
* @param {import('axios').AxiosError} error
|
11
|
-
* @returns {import('axios').AxiosResponse<import('../').EquinoxResponse>}
|
12
|
-
*/
|
13
|
-
function productNotFoundInterceptor(error) {
|
14
|
-
const segments = 'catalogs/search';
|
15
|
-
const { config, response } = error;
|
16
|
-
|
17
|
-
if (response.status === httpStatus.notFound && config.url.includes(segments)) {
|
18
|
-
const params = new URLSearchParams(config.url);
|
19
|
-
const filterParam = Array.from(params.values())[0];
|
20
|
-
const sku = getSKU(filterParam);
|
21
|
-
|
22
|
-
if (sku !== null) {
|
23
|
-
const response = {
|
24
|
-
...error.response,
|
25
|
-
data: {
|
26
|
-
product: [
|
27
|
-
productNotFound(sku)
|
28
|
-
]
|
29
|
-
},
|
30
|
-
statusText: getStatusText(error.response)
|
31
|
-
};
|
32
|
-
|
33
|
-
return response;
|
34
|
-
}
|
35
|
-
|
36
|
-
console.error('Unable to detect SKU from the given parameter', filterParam);
|
37
|
-
}
|
38
|
-
|
39
|
-
return Promise.reject(error);
|
40
|
-
}
|
41
|
-
|
42
|
-
/**
|
43
|
-
* getSKU returns the SKU from the given parameter.
|
44
|
-
* @param {string} param '\\''index_key_productId="02010489" OR index_key_skuId="02010489"'''
|
45
|
-
* @returns {string|null} SKU
|
46
|
-
*/
|
47
|
-
function getSKU(param) {
|
48
|
-
const result = param.match(/\d{8}/);
|
49
|
-
|
50
|
-
if (result === null) {
|
51
|
-
return null;
|
52
|
-
}
|
53
|
-
|
54
|
-
return result[0];
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* @param {import('axios').AxiosResponse<import('../').EquinoxErrorResponse>} [response]
|
59
|
-
* @returns {string}
|
60
|
-
*/
|
61
|
-
function getStatusText(response) {
|
62
|
-
if (response) {
|
63
|
-
const { code, message, timestamp } = response.data;
|
64
|
-
return `Floating product found -- ${timestamp} ${code}: ${message}`;
|
65
|
-
}
|
66
|
-
|
67
|
-
return '';
|
68
|
-
}
|
69
|
-
|
70
|
-
module.exports = productNotFoundInterceptor;
|