@nuskin/ns-shop 5.18.7 → 5.18.8
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/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import $ from '@nuskin/nuskinjquery';
|
|
2
2
|
import {UserService} from '@nuskin/ns-account';
|
|
3
|
-
import { retrieveToggles } from '@nuskin/ns-feature-flags';
|
|
4
3
|
import {ConfigService, events, StringService, RunConfigService, storage, NsNotQualifiedException} from '@nuskin/ns-util';
|
|
5
|
-
import
|
|
4
|
+
import ProductService from './../cart/productService'
|
|
6
5
|
import axios from 'axios';
|
|
7
6
|
|
|
8
7
|
const QUALIFICATION_URL = "/qualification/v1";
|
|
@@ -14,17 +13,6 @@ let _activeEvents = [];
|
|
|
14
13
|
let getPromise = {promise: null};
|
|
15
14
|
let managePromise = {promise: null};
|
|
16
15
|
|
|
17
|
-
let featureFlags = false
|
|
18
|
-
|
|
19
|
-
let variantMappings = {}
|
|
20
|
-
|
|
21
|
-
const checkFlag = async (flag) => {
|
|
22
|
-
if (!featureFlags) {
|
|
23
|
-
featureFlags = await retrieveToggles()
|
|
24
|
-
}
|
|
25
|
-
return featureFlags.has(flag)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
16
|
/*
|
|
29
17
|
-----------------------------
|
|
30
18
|
Private Methods
|
|
@@ -53,40 +41,6 @@ const _getHeaders = (jwt) => {
|
|
|
53
41
|
return headers;
|
|
54
42
|
};
|
|
55
43
|
|
|
56
|
-
const _mapSkusToBase = async (skuList, exclusiveProductsOnly) => {
|
|
57
|
-
|
|
58
|
-
// load product data
|
|
59
|
-
await loadVariantMappings(skuList)
|
|
60
|
-
|
|
61
|
-
return skuList
|
|
62
|
-
.map(sku => '' + sku)
|
|
63
|
-
.filter(sku => variantMappings[sku].isExclusive || !exclusiveProductsOnly)
|
|
64
|
-
.reduce((result, sku) => {
|
|
65
|
-
result[sku] = variantMappings[sku].sku
|
|
66
|
-
return result
|
|
67
|
-
}, {})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const _convertCartDataToBaseSkus = async (cartList, exclusiveProductsOnly) => {
|
|
71
|
-
|
|
72
|
-
const mappings = await _mapSkusToBase(cartList.map(entry => entry.sku), exclusiveProductsOnly)
|
|
73
|
-
|
|
74
|
-
const result = cartList
|
|
75
|
-
.filter(item => mappings[item.sku])
|
|
76
|
-
.reduce((result, item) => {
|
|
77
|
-
const baseSku = mappings[item.sku]
|
|
78
|
-
if (!result[baseSku]) {
|
|
79
|
-
result[baseSku] = {
|
|
80
|
-
sku: baseSku,
|
|
81
|
-
qty: 0
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
result[baseSku].qty += item.qty
|
|
85
|
-
return result
|
|
86
|
-
}, {})
|
|
87
|
-
return result
|
|
88
|
-
}
|
|
89
|
-
|
|
90
44
|
const _loadAddons = async (qualifications) => {
|
|
91
45
|
await Promise.all(
|
|
92
46
|
Object.keys(qualifications)
|
|
@@ -95,7 +49,9 @@ const _loadAddons = async (qualifications) => {
|
|
|
95
49
|
// eslint-disable-next-line no-async-promise-executor
|
|
96
50
|
new Promise(async (resolve) => {
|
|
97
51
|
try {
|
|
98
|
-
let productData = await ProductService.getProductBySku({
|
|
52
|
+
let productData = await ProductService.getProductBySku({
|
|
53
|
+
sku: sku
|
|
54
|
+
});
|
|
99
55
|
|
|
100
56
|
if (productData && productData.product && productData.product.addOns && Array.isArray(productData.product.addOns)) {
|
|
101
57
|
qualifications[sku].addOns = productData.product.addOns.map(element => element.sku ? element.sku : element + '')
|
|
@@ -543,12 +499,6 @@ const returnQualifications = async (sku) => {
|
|
|
543
499
|
* @returns {Promise<*>}
|
|
544
500
|
*/
|
|
545
501
|
const getQualification = async (sku) => {
|
|
546
|
-
|
|
547
|
-
const featureEnabled = await checkFlag('cx15-4373')
|
|
548
|
-
if (featureEnabled) {
|
|
549
|
-
sku = (await _mapSkusToBase([sku]))[sku]
|
|
550
|
-
}
|
|
551
|
-
|
|
552
502
|
let qualifications = await getQualifications();
|
|
553
503
|
return qualifications[sku];
|
|
554
504
|
};
|
|
@@ -561,71 +511,15 @@ const getQualification = async (sku) => {
|
|
|
561
511
|
* @returns {Promise<*>}
|
|
562
512
|
*/
|
|
563
513
|
const isQualified = async (sku, qty) => {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const cartItem = CartService.getItemData().find(item => item.sku == sku)
|
|
567
|
-
let quantityChange = qty
|
|
568
|
-
if (cartItem) {
|
|
569
|
-
quantityChange = qty - cartItem.qty
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
sku = (await _mapSkusToBase([sku]))[sku]
|
|
514
|
+
let retVal = false,
|
|
515
|
+
qualification = await getQualification(sku);
|
|
573
516
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const newCartContentsBaseSkus = await _convertCartDataToBaseSkus(
|
|
579
|
-
[...CartService.getItemData(), {sku: sku, qty: quantityChange}],
|
|
580
|
-
true)
|
|
581
|
-
const qualification = await getQualification(sku);
|
|
582
|
-
|
|
583
|
-
return qualification && qualification.quantity >= newCartContentsBaseSkus[sku].qty && qualification.isConsumable
|
|
584
|
-
} else {
|
|
585
|
-
let retVal = false,
|
|
586
|
-
qualification = await getQualification(sku);
|
|
587
|
-
|
|
588
|
-
if (qualification && qualification.quantity >= qty) {
|
|
589
|
-
retVal = qualification.isConsumable;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return retVal;
|
|
517
|
+
if (qualification && qualification.quantity >= qty) {
|
|
518
|
+
retVal = qualification.isConsumable;
|
|
593
519
|
}
|
|
594
|
-
};
|
|
595
520
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
* @param {*} skuList
|
|
599
|
-
*/
|
|
600
|
-
const loadVariantMappings = async (skuList, loadBaseProducts) => {
|
|
601
|
-
const promises = skuList
|
|
602
|
-
.map(sku => '' + sku)
|
|
603
|
-
.filter(sku => !variantMappings[sku])
|
|
604
|
-
.map(sku => ProductService.getProductBySku({sku: sku})
|
|
605
|
-
.then(result => {
|
|
606
|
-
const sku = result.product.sku
|
|
607
|
-
variantMappings[sku] = {
|
|
608
|
-
isExclusive: result.product.isExclusive,
|
|
609
|
-
sku: result.product.baseSku || sku
|
|
610
|
-
}
|
|
611
|
-
return result;
|
|
612
|
-
})
|
|
613
|
-
)
|
|
614
|
-
let products = await Promise.all(promises)
|
|
615
|
-
|
|
616
|
-
// once we have loaded the variants, also load all their parent products
|
|
617
|
-
|
|
618
|
-
if (loadBaseProducts) {
|
|
619
|
-
const baseProductSkus = products
|
|
620
|
-
.map(result => result.product)
|
|
621
|
-
.filter(product => product.baseSku)
|
|
622
|
-
.map(product => product.baseSku)
|
|
623
|
-
|
|
624
|
-
if (baseProductSkus.length > 0) {
|
|
625
|
-
loadVariantMappings(baseProductSkus, false)
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
521
|
+
return retVal;
|
|
522
|
+
};
|
|
629
523
|
|
|
630
524
|
/**
|
|
631
525
|
* Return whether to show qualification banner
|
|
@@ -654,7 +548,6 @@ $(document).ready(_setListeners);
|
|
|
654
548
|
const qualificationService = {
|
|
655
549
|
_setListeners, // Only exposed for unit testing purposes this is called above in the jquery ready function
|
|
656
550
|
_clearQualifications, // exposed for unit testing
|
|
657
|
-
loadVariantMappings,
|
|
658
551
|
getQualifications,
|
|
659
552
|
getQualification,
|
|
660
553
|
isQualified,
|