@nuskin/ns-shop 7.7.0-pa-87.4 → 7.7.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-pa-87.4",
3
+ "version": "7.7.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": {
@@ -26,7 +26,7 @@
26
26
  "@nuskin/ns-common-lib": "1.4.8",
27
27
  "@nuskin/ns-feature-flags": "1.5.0",
28
28
  "@nuskin/ns-loyalty-web": "1.5.7",
29
- "@nuskin/ns-product-lib": "2.21.0",
29
+ "@nuskin/ns-product-lib": "2.20.0",
30
30
  "@nuskin/nuskinjquery": "2.3.1",
31
31
  "@nuskin/order-model": "3.1.3",
32
32
  "@nuskin/product-lib": "2.4.0",
@@ -6,7 +6,6 @@ import {AdrService, Product, ScanCard, CurrencyService} from '@nuskin/ns-shop';
6
6
  import {UserService, AccountManager} from '@nuskin/ns-account';
7
7
  import ProductService from './productService';
8
8
  import Cart from './cart.js';
9
- import {OrderType} from '../order/orderType.js';
10
9
  import AdrEditService from '../adr/AdrEditService.js';
11
10
  import QualificationService from '@nuskin/exclusive-offer-sdk'
12
11
  import {ProductStatus} from '@nuskin/ns-product-lib';
@@ -36,7 +35,6 @@ export default {
36
35
  hasEventItems,
37
36
  hasPreviewItems,
38
37
  hasDangerousGoods,
39
- getCartWeight,
40
38
  getItemCnt,
41
39
  addProductToCart,
42
40
  addSkuToCart,
@@ -57,6 +55,7 @@ export default {
57
55
  adrHasAgelocMe,
58
56
  setSignupMode,
59
57
  inSignupMode,
58
+ canUserAddToCart,
60
59
  minAdrPsvMet,
61
60
  checkProductLanguages,
62
61
  scanQualifiedCnt,
@@ -301,29 +300,14 @@ function hasPreviewItems() {
301
300
  return _getCart().hasPreviewItems();
302
301
  }
303
302
 
304
- function _getItemsByOrderType(orderType) {
305
- if (orderType == OrderType.SHIP_IMMEDIATE) return _getCart().getItems({cartItems: true});
306
- else if (orderType == OrderType.ADR_CREATE) return _getCart().getItems({cartAdrItems: true});
307
- else return _getCart().getItems({cartOrderItems: true});
308
- }
309
-
310
- function hasDangerousGoods(orderType) {
303
+ function hasDangerousGoods(options = {cartItems: true}) {
311
304
  let retVal = false;
312
- _getItemsByOrderType(orderType).forEach((item) => {
305
+ _getCart().getItems(options).forEach((item) => {
313
306
  retVal = retVal || item.product.dangerousGoods;
314
307
  });
315
308
  return retVal;
316
309
  }
317
310
 
318
- function getCartWeight(orderType) {
319
- let retVal = 0.0;
320
-
321
- _getItemsByOrderType(orderType).forEach((item) => {
322
- retVal += item.qty * (item.product.grossWeight || 0.0);
323
- });
324
- return retVal;
325
- }
326
-
327
311
  function getItemCnt(options) {
328
312
  return _getCart().getItemCnt(options);
329
313
  }
@@ -688,6 +672,50 @@ function inSignupMode() {
688
672
  return cart ? cart.inSignup : false;
689
673
  }
690
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.canUserAddToCart();
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 canUserAddToCart() {
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.homeMarketPurchasingOnly) || [];
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
+
691
719
  function minAdrPsvMet() {
692
720
  let retVal = true,
693
721
  cart = _getCart(),
@@ -837,8 +865,6 @@ function syncCartItemToSapItem(sapItemKey, cartItemKey = null) {
837
865
  cartItem.redeem = sapItem.redeem;
838
866
  cartItem.qtyRedeemWithPoints = sapItem.qtyRedeemWithPoints;
839
867
  cartItem.product.subPriceFlag = sapItem.product.subPriceFlag;
840
- cartItem.product.grossWeight = sapItem.product.grossWeight;
841
- cartItem.product.weightUnit = sapItem.product.weightUnit;
842
868
  cart.addCartItem(cartItem, true);
843
869
  setCart(cart, false);
844
870
  }
@@ -29,6 +29,7 @@ newShop.Order = function(orderData){
29
29
 
30
30
  let selectedAddress;
31
31
  let selectedShippingMethod;
32
+ let simulatedShippingMethod = {};
32
33
  let shippingAvailableMethods;
33
34
  let availableAddressTypes;
34
35
  let selectedPayment;
@@ -111,6 +112,7 @@ newShop.Order = function(orderData){
111
112
  simulateWithoutShipping = orderData.simulateWithoutShipping;
112
113
  externalPayment = orderData.externalPayment;
113
114
  selectedShippingMethod = orderData.selectedShippingMethod;
115
+ simulatedShippingMethod = orderData.simulatedShippingMethod || {};
114
116
  shippingAvailableMethods = orderData.shippingAvailableMethods;
115
117
  availableAddressTypes = orderData.availableAddressTypes;
116
118
  errorResponseInfo = orderData.errorResponseInfo;
@@ -265,6 +267,7 @@ newShop.Order = function(orderData){
265
267
  order.simulateWithoutShipping = simulateWithoutShipping;
266
268
  order.externalPayment = externalPayment;
267
269
  order.selectedShippingMethod = selectedShippingMethod;
270
+ order.simulatedShippingMethod = simulatedShippingMethod || {};
268
271
  order.shippingAvailableMethods = shippingAvailableMethods;
269
272
  order.availableAddressTypes = availableAddressTypes;
270
273
  order.errorResponseInfo = errorResponseInfo;
@@ -471,6 +474,14 @@ newShop.Order = function(orderData){
471
474
  selectedShippingMethod = _selectedShippingMethod;
472
475
  }
473
476
  },
477
+ simulatedShippingMethod: {
478
+ get: function() {
479
+ return simulatedShippingMethod;
480
+ },
481
+ set: function(_simulatedShippingMethod) {
482
+ simulatedShippingMethod = _simulatedShippingMethod;
483
+ }
484
+ },
474
485
  shippingAvailableMethods: {
475
486
  get: function() {
476
487
  return shippingAvailableMethods;
@@ -1,13 +1,12 @@
1
1
  import $ from '@nuskin/nuskinjquery';
2
2
  import {Agelocme, CartService, ShippingAddress, ShopContextService, OrderManager, SalesOrder,
3
- Product, ProductService, ExternalPaymentService, ProcessorCode} from "../shop.js";
3
+ PickupUtil, Product, ProductService, ExternalPaymentService, ProcessorCode} from "../shop.js";
4
4
  import {RunConfigService, events, util, PersonalOfferStorageService, BrowserDetection, ShoppingContext, UrlService} from "@nuskin/ns-util";
5
5
  import {getCachedConfigField} from '@nuskin/configuration-sdk';
6
6
  import {UserService} from "@nuskin/ns-account";
7
7
  import PaymentAdapter from '../payment/PaymentAdapter';
8
- import PickupUtil from '../shipping/pickupUtil';
9
- import {Order} from '@nuskin/order-model';
10
- import {storage} from "@nuskin/ns-util";
8
+ import pickupUtil from '../shipping/pickupUtil';
9
+ import { storage } from "@nuskin/ns-util";
11
10
 
12
11
  let splitLineItems = [];
13
12
  const utmInfo = storage.getItem(storage.metadata.UTM_INFO) || {};
@@ -171,16 +170,12 @@ const getDefaultShipCode = (osmc) => {
171
170
  if (useShipMethodsApi) {
172
171
  const csDefaultCode = getCachedConfigField('defaultShipMethod');
173
172
  const shipMethods = PickupUtil.getStoredShipMethods();
174
- if (shipMethods?.length > 0) {
175
- const firstSm = shipMethods[0].Code;
176
- const defaultShipMethod = shipMethods.find((sm) => sm.Code === osmc);
177
- if (!defaultShipMethod) {
178
- defaultCode = shipMethods.find((sm) => sm.Code === csDefaultCode) ? csDefaultCode : firstSm;
179
- } else {
180
- defaultCode = defaultShipMethod.Code;
181
- }
173
+ const firstSm = shipMethods.length > 0 ? shipMethods[0].Code : '';
174
+ const defaultShipMethod = shipMethods.find((sm) => sm.Code === osmc);
175
+ if (!defaultShipMethod) {
176
+ defaultCode = shipMethods.find((sm) => sm.Code === csDefaultCode) ? csDefaultCode : firstSm;
182
177
  } else {
183
- defaultCode = csDefaultCode;
178
+ defaultCode = defaultShipMethod.Code;
184
179
  }
185
180
  }
186
181
 
@@ -506,7 +501,7 @@ const populateCategory = (salesOrder) => {
506
501
  } else if (utmMedium && utmMedium.toLowerCase().includes('paidsearch')) {
507
502
  salesOrder.Category = 'PAIDSEARCH';
508
503
  } else if (utmMedium && utmMedium.toLowerCase().includes('paidsocial')) {
509
- salesOrder.Category = 'PAIDAD';
504
+ salesOrder.Category = 'PAIDAD';
510
505
  } else {
511
506
  salesOrder.Category = 'WEB';
512
507
  }
@@ -655,10 +650,6 @@ const syncProductItems = async (order, sapProducts, adr, includeSapItems) => {
655
650
  label = custom.Value;
656
651
  } else if (custom.Key === 'SUB_PRICE') {
657
652
  newItem.subPriceFlag = true;
658
- } else if (custom.Key === 'GROSSWEIGHT') {
659
- newItem.grossWeight = parseFloat(custom.Value);
660
- } else if (custom.Key === 'WEIGHTUNIT') {
661
- newItem.weightUnit = custom.Value;
662
653
  }
663
654
  });
664
655
  if (code != null || name !== null || label != null) {
@@ -1129,18 +1120,6 @@ const populateSalesOrder = (action, adr) => {
1129
1120
  return salesOrder;
1130
1121
  };
1131
1122
 
1132
- const getShipMethods = async (salesOrderDetail, orderType) => {
1133
- let shipMethods;
1134
- const useShipMethodsApi = getCachedConfigField('useShipMethodsApi');
1135
- if (useShipMethodsApi) {
1136
- await PickupUtil.loadShipMethods(Order.fromSalesOrderRequest(populateSalesOrder('SIMULATE')), orderType);
1137
- shipMethods = await PickupUtil.getShipMethods();
1138
- } else {
1139
- shipMethods = salesOrderDetail.ShippingAvailableMethods
1140
- }
1141
- return shipMethods
1142
- }
1143
-
1144
1123
  /**
1145
1124
  * Maps Sales order detail object to the order object
1146
1125
  * @param {Object} salesOrderDetail
@@ -1160,12 +1139,14 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1160
1139
  order.shippingPayWithPoints = salesOrderDetail.Custom.map(item => item.Key).indexOf('ZZUSE_PTS') > -1;
1161
1140
  }
1162
1141
 
1163
- await syncProductItems(order, salesOrderDetail.LineItemDetails, order.adr ? adr : null);
1164
-
1165
1142
  const useShipMethodsApi = getCachedConfigField('useShipMethodsApi');
1166
1143
  if (useShipMethodsApi || salesOrderDetail.ShippingAvailableMethods && salesOrderDetail.ShippingAvailableMethods.length > 0) {
1167
- const shipMethods = await getShipMethods(salesOrderDetail, order.orderType);
1144
+ const shipMethods = useShipMethodsApi ? await pickupUtil.getShipMethods() : salesOrderDetail.ShippingAvailableMethods;
1168
1145
  order.shippingAvailableMethods = sortShippingAvailableMethods(shipMethods);
1146
+ order.simulatedShippingMethod =
1147
+ order.shippingAvailableMethods.find(
1148
+ (sam) => sam.Code === salesOrderDetail.Shipping.ShippingMethod.Code
1149
+ ) || order.shippingAvailableMethods[0];
1169
1150
 
1170
1151
  setShippingAvailableMethodsPickupInfo(order.shippingAvailableMethods);
1171
1152
  setSelectedShipMethod(order, salesOrderDetail.Shipping.ShippingMethod);
@@ -1175,7 +1156,7 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1175
1156
  let oldPup = null;
1176
1157
  if (!useShipMethodsApi) oldPup = salesOrderDetail.Custom;
1177
1158
  let newPup = null;
1178
- if (useShipMethodsApi) newPup = await PickupUtil.getPickupPoints();
1159
+ if (useShipMethodsApi) newPup = await pickupUtil.getPickupPoints();
1179
1160
  setPickupPoints(oldPup, newPup, order);
1180
1161
  }
1181
1162
  }
@@ -1185,6 +1166,7 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1185
1166
  syncShipping(salesOrderDetail.Shipping, order);
1186
1167
  }
1187
1168
 
1169
+ await syncProductItems(order, salesOrderDetail.LineItemDetails, order.adr ? adr : null);
1188
1170
  syncOrderTotals(salesOrderDetail.OrderTotals, order.orderTotals);
1189
1171
  syncPayment(salesOrderDetail.Payment, order.selectedPayment);
1190
1172
  OrderManager.saveOrders();
@@ -5,7 +5,6 @@ import {OrderType} from './orderType.js';
5
5
  import {storage, events, RunConfigService} from "@nuskin/ns-util";
6
6
  import {UserService} from "@nuskin/ns-account";
7
7
  import {AdrService, CartService, CheckoutModeService} from "../shop";
8
- import {getCachedConfigField} from '@nuskin/configuration-sdk';
9
8
 
10
9
  const ORDER_STORAGE_KEY = storage.metadata.ORDER_STORAGE_KEY,
11
10
  ORDER_PREFS_STORAGE_KEY = storage.metadata.ORDER_PREFS_STORAGE_KEY,
@@ -74,14 +73,6 @@ const _initOrder = () => {
74
73
  result.selectedAddress = orderPreferences.selectedAddress;
75
74
  }
76
75
  }
77
- if (!result.selectedShippingMethod) {
78
- if (getCachedConfigField('useShipMethodsApi')) {
79
- const csDefaultCode = getCachedConfigField('defaultShipMethod');
80
- if (csDefaultCode) {
81
- result.selectedShippingMethod = {Code: csDefaultCode, PickUpLocation: ''};
82
- }
83
- }
84
- }
85
76
 
86
77
  return new Order(result);
87
78
  };
@@ -1,6 +1,7 @@
1
1
  import {getCachedConfiguration} from '@nuskin/configuration-sdk';
2
+ import {Order} from '@nuskin/order-model';
2
3
  import {RunConfigService} from '@nuskin/ns-util';
3
- import {OrderManager, CartService, OrderType} from '../shop';
4
+ import {OrderManager, CartService, OrderType, OrderAdapter} from '../shop';
4
5
  import axios from 'axios';
5
6
 
6
7
  let PickupUtil = function() {
@@ -196,7 +197,8 @@ let PickupUtil = function() {
196
197
  return same
197
198
  }
198
199
 
199
- function loadShipMethods(order, orderType) {
200
+ function loadShipMethods() {
201
+ const order = Order.fromSalesOrderRequest(OrderAdapter.populateSalesOrder('SIMULATE'));
200
202
  const {metapackMarket} = getCachedConfiguration('Checkout');
201
203
 
202
204
  if (metapackMarket) {
@@ -204,8 +206,7 @@ let PickupUtil = function() {
204
206
  const payload = {
205
207
  order,
206
208
  orderValue: getOrderValue(),
207
- dangerousGoods: CartService.hasDangerousGoods(orderType),
208
- weight: CartService.getCartWeight(orderType),
209
+ dangerousGoods: CartService.hasDangerousGoods(),
209
210
  language: runConfig.language,
210
211
  country: runConfig.country
211
212
  };