@nuskin/ns-shop 7.6.4 → 7.7.0-cdb-1.1
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 +1 -1
- package/src/cart/cartService.js +45 -0
package/package.json
CHANGED
package/src/cart/cartService.js
CHANGED
|
@@ -55,6 +55,7 @@ export default {
|
|
|
55
55
|
adrHasAgelocMe,
|
|
56
56
|
setSignupMode,
|
|
57
57
|
inSignupMode,
|
|
58
|
+
currentUserCanAddToCart,
|
|
58
59
|
minAdrPsvMet,
|
|
59
60
|
checkProductLanguages,
|
|
60
61
|
scanQualifiedCnt,
|
|
@@ -671,6 +672,50 @@ function inSignupMode() {
|
|
|
671
672
|
return cart ? cart.inSignup : false;
|
|
672
673
|
}
|
|
673
674
|
|
|
675
|
+
/**
|
|
676
|
+
* Determines if the current user has permission to add items to cart based on market restrictions.
|
|
677
|
+
* Checks if users from markets configured in 'foreignOrderingRestrictedMarkets' are attempting
|
|
678
|
+
* to add items in foreign markets.
|
|
679
|
+
*
|
|
680
|
+
* @memberof CartService
|
|
681
|
+
* @example
|
|
682
|
+
* const canAdd = await CartService.currentUserCanAddToCart();
|
|
683
|
+
* if (!canAdd) {
|
|
684
|
+
* // Show popup notification to user
|
|
685
|
+
* }
|
|
686
|
+
*
|
|
687
|
+
* @returns {Promise<boolean>} Promise that resolves to true if current user can add items to cart, false if restricted
|
|
688
|
+
*/
|
|
689
|
+
async function currentUserCanAddToCart() {
|
|
690
|
+
// If no user is logged in, allow adding to cart (no restrictions for anonymous users)
|
|
691
|
+
const user = UserService.getUser();
|
|
692
|
+
if (!user) {
|
|
693
|
+
return true;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// Get current market and user's home market
|
|
697
|
+
const runConfig = RunConfigService.getRunConfig();
|
|
698
|
+
const currentMarket = runConfig ? runConfig.country : null;
|
|
699
|
+
const userHomeMarket = user.countryCd;
|
|
700
|
+
|
|
701
|
+
// If we can't determine markets, allow adding to cart (fail open)
|
|
702
|
+
if (!currentMarket || !userHomeMarket) {
|
|
703
|
+
return true;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// Get Cart configuration to access foreign ordering restrictions
|
|
707
|
+
const { Cart: cartConfig } = await getConfiguration(['Cart']);
|
|
708
|
+
const foreignOrderingRestrictedMarkets = (cartConfig && cartConfig.foreignOrderingRestrictedMarkets) || [];
|
|
709
|
+
|
|
710
|
+
// Check if user's home market restricts foreign ordering
|
|
711
|
+
if (foreignOrderingRestrictedMarkets.includes(userHomeMarket) && currentMarket !== userHomeMarket) {
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// All other cases are allowed
|
|
716
|
+
return true;
|
|
717
|
+
}
|
|
718
|
+
|
|
674
719
|
function minAdrPsvMet() {
|
|
675
720
|
let retVal = true,
|
|
676
721
|
cart = _getCart(),
|