@nuskin/ns-shop 7.7.0 → 7.8.0-pa-902.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-shop",
3
- "version": "7.7.0",
3
+ "version": "7.8.0-pa-902.1",
4
4
  "description": "The description that will amaze and astound your audience when they read it",
5
5
  "main": "src/shop.js",
6
6
  "scripts": {
@@ -42,7 +42,7 @@
42
42
  "@nuskin/ns-account": "5.13.0",
43
43
  "@nuskin/ns-jsanalyzer": "1.0.1",
44
44
  "@nuskin/ns-product": "3.51.0",
45
- "@nuskin/ns-util": "4.7.2",
45
+ "@nuskin/ns-util": "4.8.0",
46
46
  "axios-mock-adapter": "1.22.0",
47
47
  "axios": "1.9.0",
48
48
  "babel-cli": "6.26.0",
@@ -57,6 +57,7 @@ export default {
57
57
  adrHasAgelocMe,
58
58
  setSignupMode,
59
59
  inSignupMode,
60
+ canUserAddToCart,
60
61
  minAdrPsvMet,
61
62
  checkProductLanguages,
62
63
  scanQualifiedCnt,
@@ -371,6 +372,10 @@ function itemIsAvailable(product) {
371
372
  */
372
373
  async function addProductToCart(options) {
373
374
  await awaitForConfig();
375
+ if (!await canUserAddToCart()) {
376
+ events.setValue(events.shop.HOME_MARKET_ONLY_RESTRICTED, !(await canUserAddToCart()));
377
+ return;
378
+ }
374
379
  let cart = _getCart();
375
380
 
376
381
  if (!options.sapLineId && !itemIsAvailable(options.product)) {
@@ -439,6 +444,11 @@ async function addProductToCart(options) {
439
444
  * }
440
445
  */
441
446
  async function addSkuToCart(options) {
447
+ if (!await canUserAddToCart()) {
448
+ events.setValue(events.shop.HOME_MARKET_ONLY_RESTRICTED, !(await canUserAddToCart()));
449
+ return;
450
+ }
451
+
442
452
  let retVal,
443
453
  response = await ProductService.getProductBySku(options),
444
454
  product = response.success && response.product;
@@ -688,6 +698,50 @@ function inSignupMode() {
688
698
  return cart ? cart.inSignup : false;
689
699
  }
690
700
 
701
+ /**
702
+ * Determines if the current user has permission to add items to cart based on market restrictions.
703
+ * Checks if users from markets configured in 'foreignOrderingRestrictedMarkets' are attempting
704
+ * to add items in foreign markets.
705
+ *
706
+ * @memberof CartService
707
+ * @example
708
+ * const canAdd = await CartService.canUserAddToCart();
709
+ * if (!canAdd) {
710
+ * // Show popup notification to user
711
+ * }
712
+ *
713
+ * @returns {Promise<boolean>} Promise that resolves to true if current user can add items to cart, false if restricted
714
+ */
715
+ async function canUserAddToCart() {
716
+ // If no user is logged in, allow adding to cart (no restrictions for anonymous users)
717
+ const user = UserService.getUser();
718
+ if (!user) {
719
+ return true;
720
+ }
721
+
722
+ // Get current market and user's home market
723
+ const runConfig = RunConfigService.getRunConfig();
724
+ const currentMarket = runConfig ? runConfig.country : null;
725
+ const userHomeMarket = user.countryCd;
726
+
727
+ // If we can't determine markets, allow adding to cart (fail open)
728
+ if (!currentMarket || !userHomeMarket) {
729
+ return true;
730
+ }
731
+
732
+ // Get Cart configuration to access foreign ordering restrictions
733
+ const { Cart: cartConfig } = await getConfiguration(['Cart']);
734
+ const foreignOrderingRestrictedMarkets = (cartConfig && cartConfig.homeMarketPurchasingOnly) || [];
735
+
736
+ // Check if user's home market restricts foreign ordering
737
+ if (foreignOrderingRestrictedMarkets.includes(userHomeMarket) && currentMarket !== userHomeMarket) {
738
+ return false;
739
+ }
740
+
741
+ // All other cases are allowed
742
+ return true;
743
+ }
744
+
691
745
  function minAdrPsvMet() {
692
746
  let retVal = true,
693
747
  cart = _getCart(),
@@ -439,11 +439,13 @@ const updateAnonymousPersistedCart = async (cartId, payload) => {
439
439
  */
440
440
  const removePersistedCart = async (cartId) => {
441
441
  const user = UserService.getUser();
442
+ const {country} = RunConfigService.getRunConfig();
443
+
442
444
  try {
443
445
  if (user && cartId) {
444
446
  await axios({
445
447
  method: 'DELETE',
446
- url: getUrl('deleteCart', cartId, {accountId: user.id}),
448
+ url: getUrl('deleteCart', cartId, {accountId: user.id, country}),
447
449
  headers: getHeaders(user.eid)
448
450
  });
449
451
  CartService.setCartProperties({id: '', version: -1});