@nuskin/ns-shop 6.7.2 → 6.7.3
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
package/src/cart/cartService.js
CHANGED
|
@@ -7,8 +7,7 @@ import {UserService, AccountManager} from '@nuskin/ns-account';
|
|
|
7
7
|
import ProductService from './productService';
|
|
8
8
|
import Cart from './cart.js';
|
|
9
9
|
import AdrEditService from '../adr/AdrEditService.js';
|
|
10
|
-
import
|
|
11
|
-
import { default as NewQualificationService } from '@nuskin/exclusive-offer-sdk';
|
|
10
|
+
import QualificationService from '../qualification/qualificationService';
|
|
12
11
|
import {ProductStatus} from '@nuskin/ns-product-lib';
|
|
13
12
|
import webLoyalty from '@nuskin/ns-loyalty-web';
|
|
14
13
|
import axios from 'axios';
|
|
@@ -106,22 +105,6 @@ const checkFlag = async (flag) => {
|
|
|
106
105
|
}
|
|
107
106
|
checkFlag()
|
|
108
107
|
|
|
109
|
-
const getQualificationService = async () => {
|
|
110
|
-
try {
|
|
111
|
-
const [
|
|
112
|
-
flagSet,
|
|
113
|
-
configEnabled
|
|
114
|
-
] = await Promise.all([
|
|
115
|
-
checkFlag('cx15_use_new_exclusive_offer_api'),
|
|
116
|
-
getConfiguration(['Equinox_Markets']).then(configuration => configuration.Equinox_Markets.active)
|
|
117
|
-
])
|
|
118
|
-
return flagSet || configEnabled ? NewQualificationService : OldQualificationService;
|
|
119
|
-
} catch (e) {
|
|
120
|
-
console.error('error retrieving configuration. Defaulting to Legacy exclusive offer service', e)
|
|
121
|
-
return OldQualificationService
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
108
|
/**
|
|
126
109
|
*
|
|
127
110
|
* @memberof CartService
|
|
@@ -474,7 +457,7 @@ async function addSkuToCart(options) {
|
|
|
474
457
|
|
|
475
458
|
async function getBaseSkuCartQuantity(baseSku) {
|
|
476
459
|
await awaitForConfig();
|
|
477
|
-
const cartContents = await
|
|
460
|
+
const cartContents = await QualificationService.convertCartDataToBaseSkus(_getCart().getItemData(), true) || {}
|
|
478
461
|
const baseSkuData = cartContents[baseSku] || {}
|
|
479
462
|
const quantity = baseSkuData.qty || 0
|
|
480
463
|
return quantity
|
|
@@ -504,8 +487,7 @@ async function getAddToCartQty(product) {
|
|
|
504
487
|
retVal = product.maxQuantity - cartQty;
|
|
505
488
|
if (product.isExclusive) {
|
|
506
489
|
try {
|
|
507
|
-
const
|
|
508
|
-
const qual = await QualificationService.getQualification(product.sku)
|
|
490
|
+
const qual = QualificationService.getQualification(product.sku)
|
|
509
491
|
const productIdentifier = qual.productId || qual.sku;
|
|
510
492
|
cartQty = await getBaseSkuCartQuantity(productIdentifier)
|
|
511
493
|
retVal = product.maxQuantity - cartQty;
|
|
@@ -823,7 +805,6 @@ async function checkItemAvailability() {
|
|
|
823
805
|
// get qualifications for product
|
|
824
806
|
const response = await ProductService.getProductBySku({sku: item.product.sku});
|
|
825
807
|
const productInfo = response.success && response.product;
|
|
826
|
-
const QualificationService = await getQualificationService()
|
|
827
808
|
let qual = null
|
|
828
809
|
if (productInfo.equinoxProductId) {
|
|
829
810
|
qual = await QualificationService.getQualification(productInfo.equinoxProductId)
|
|
@@ -864,7 +845,7 @@ async function checkItemAvailability() {
|
|
|
864
845
|
* @private
|
|
865
846
|
*/
|
|
866
847
|
async function _checkQualification(sku, newQty) {
|
|
867
|
-
let isQualified = await
|
|
848
|
+
let isQualified = await QualificationService.isQualified(sku, newQty, _getCart().getItemData());
|
|
868
849
|
|
|
869
850
|
if (!isQualified) {
|
|
870
851
|
let str = 'You are not qualified to purchase this product';
|
|
@@ -878,7 +859,7 @@ async function _checkQualification(sku, newQty) {
|
|
|
878
859
|
}
|
|
879
860
|
|
|
880
861
|
async function _adjustToQualificationQuantity(options, origQty) {
|
|
881
|
-
const qualQty = await
|
|
862
|
+
const qualQty = await QualificationService.getQualifiedQty(options.product.sku);
|
|
882
863
|
|
|
883
864
|
if (qualQty < origQty + options.qty) {
|
|
884
865
|
if (qualQty < origQty) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import $ from '@nuskin/nuskinjquery';
|
|
2
2
|
import {UserService} from '@nuskin/ns-account';
|
|
3
3
|
import {retrieveTogglesBasedOnEnvironment} from '@nuskin/ns-feature-flags';
|
|
4
|
+
import { getCachedConfigField, getConfiguration } from '@nuskin/configuration-sdk';
|
|
4
5
|
import {
|
|
5
6
|
events,
|
|
6
7
|
StringService,
|
|
@@ -10,8 +11,9 @@ import {
|
|
|
10
11
|
UrlService
|
|
11
12
|
} from '@nuskin/ns-util';
|
|
12
13
|
import {CartService} from '@nuskin/ns-shop';
|
|
13
|
-
import {getCachedConfigField} from '@nuskin/configuration-sdk';
|
|
14
14
|
import {ProductDataService} from '@nuskin/ns-product'
|
|
15
|
+
import { default as NewQualificationService } from '@nuskin/exclusive-offer-sdk';
|
|
16
|
+
|
|
15
17
|
import axios from 'axios';
|
|
16
18
|
|
|
17
19
|
const QUALIFICATION_URL = "/qualification/v1";
|
|
@@ -23,14 +25,19 @@ let _activeEvents = [];
|
|
|
23
25
|
let getPromise = {promise: null};
|
|
24
26
|
let managePromise = {promise: null};
|
|
25
27
|
|
|
26
|
-
let featureFlags = false
|
|
27
|
-
|
|
28
28
|
let variantMappings = {}
|
|
29
29
|
|
|
30
|
+
let flagsPromise = null
|
|
31
|
+
let featureFlags = false
|
|
30
32
|
const checkFlag = async (flag) => {
|
|
33
|
+
if (!featureFlags && !flagsPromise) {
|
|
34
|
+
flagsPromise = retrieveTogglesBasedOnEnvironment().then(flagsFromServer => featureFlags = flagsFromServer)
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
if (!featureFlags) {
|
|
32
|
-
|
|
38
|
+
await flagsPromise
|
|
33
39
|
}
|
|
40
|
+
|
|
34
41
|
return featureFlags.has(flag)
|
|
35
42
|
}
|
|
36
43
|
|
|
@@ -686,7 +693,7 @@ const getEarlyAccessQualificationModal = () => {
|
|
|
686
693
|
|
|
687
694
|
$(document).ready(_setListeners);
|
|
688
695
|
|
|
689
|
-
const
|
|
696
|
+
const OldQualificationService = {
|
|
690
697
|
_clearQualifications, // exposed for unit testing
|
|
691
698
|
_setListeners, // Only exposed for unit testing purposes this is called above in the jquery ready function
|
|
692
699
|
claimQualifications,
|
|
@@ -706,4 +713,42 @@ const qualificationService = {
|
|
|
706
713
|
transferQualifications
|
|
707
714
|
};
|
|
708
715
|
|
|
709
|
-
|
|
716
|
+
/*
|
|
717
|
+
The code below will globally switch this service over to the new exclusive offer service in markets where that is appropriate
|
|
718
|
+
|
|
719
|
+
For each method in the service, it will switch between old and new service based on the equinox configuration and feature flag.
|
|
720
|
+
If the method isn't in the new service or if there is an error fetching, it will default to the old one
|
|
721
|
+
*/
|
|
722
|
+
const getQualificationService = async () => {
|
|
723
|
+
try {
|
|
724
|
+
const [
|
|
725
|
+
flagSet,
|
|
726
|
+
configEnabled
|
|
727
|
+
] = await Promise.all([
|
|
728
|
+
checkFlag('cx15_use_new_exclusive_offer_api'),
|
|
729
|
+
getConfiguration(['Equinox_Markets']).then(configuration => configuration.Equinox_Markets.active)
|
|
730
|
+
])
|
|
731
|
+
return flagSet || configEnabled ? NewQualificationService : OldQualificationService;
|
|
732
|
+
} catch (e) {
|
|
733
|
+
console.error('error retrieving configuration. Defaulting to Legacy exclusive offer service', e)
|
|
734
|
+
return OldQualificationService
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const invokeQualificationServiceMethod = async (params, functionName) => {
|
|
739
|
+
const qualificationService = await getQualificationService()
|
|
740
|
+
return qualificationService[functionName](...params)
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
const QualificationService = Object.keys(OldQualificationService)
|
|
744
|
+
.reduce((QualificationService, functionName) => {
|
|
745
|
+
if (NewQualificationService[functionName]) {
|
|
746
|
+
QualificationService[functionName] = (...params) => invokeQualificationServiceMethod(params, functionName)
|
|
747
|
+
} else {
|
|
748
|
+
QualificationService[functionName] = OldQualificationService[functionName]
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
return QualificationService
|
|
752
|
+
}, {})
|
|
753
|
+
|
|
754
|
+
export default QualificationService;
|