@nuskin/ns-shop 7.7.0-pa-902.6 → 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-pa-902.6",
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": {
@@ -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.20.0",
29
+ "@nuskin/ns-product-lib": "2.21.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,6 +6,7 @@ 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';
9
10
  import AdrEditService from '../adr/AdrEditService.js';
10
11
  import QualificationService from '@nuskin/exclusive-offer-sdk'
11
12
  import {ProductStatus} from '@nuskin/ns-product-lib';
@@ -35,6 +36,7 @@ export default {
35
36
  hasEventItems,
36
37
  hasPreviewItems,
37
38
  hasDangerousGoods,
39
+ getCartWeight,
38
40
  getItemCnt,
39
41
  addProductToCart,
40
42
  addSkuToCart,
@@ -300,14 +302,29 @@ function hasPreviewItems() {
300
302
  return _getCart().hasPreviewItems();
301
303
  }
302
304
 
303
- function hasDangerousGoods(options = {cartItems: true}) {
305
+ function _getItemsByOrderType(orderType) {
306
+ if (orderType == OrderType.SHIP_IMMEDIATE) return _getCart().getItems({cartItems: true});
307
+ else if (orderType == OrderType.ADR_CREATE) return _getCart().getItems({cartAdrItems: true});
308
+ else return _getCart().getItems({cartOrderItems: true});
309
+ }
310
+
311
+ function hasDangerousGoods(orderType) {
304
312
  let retVal = false;
305
- _getCart().getItems(options).forEach((item) => {
313
+ _getItemsByOrderType(orderType).forEach((item) => {
306
314
  retVal = retVal || item.product.dangerousGoods;
307
315
  });
308
316
  return retVal;
309
317
  }
310
318
 
319
+ function getCartWeight(orderType) {
320
+ let retVal = 0.0;
321
+
322
+ _getItemsByOrderType(orderType).forEach((item) => {
323
+ retVal += item.qty * (item.product.grossWeight || 0.0);
324
+ });
325
+ return retVal;
326
+ }
327
+
311
328
  function getItemCnt(options) {
312
329
  return _getCart().getItemCnt(options);
313
330
  }
@@ -874,6 +891,8 @@ function syncCartItemToSapItem(sapItemKey, cartItemKey = null) {
874
891
  cartItem.redeem = sapItem.redeem;
875
892
  cartItem.qtyRedeemWithPoints = sapItem.qtyRedeemWithPoints;
876
893
  cartItem.product.subPriceFlag = sapItem.product.subPriceFlag;
894
+ cartItem.product.grossWeight = sapItem.product.grossWeight;
895
+ cartItem.product.weightUnit = sapItem.product.weightUnit;
877
896
  cart.addCartItem(cartItem, true);
878
897
  setCart(cart, false);
879
898
  }
@@ -29,7 +29,6 @@ newShop.Order = function(orderData){
29
29
 
30
30
  let selectedAddress;
31
31
  let selectedShippingMethod;
32
- let simulatedShippingMethod = {};
33
32
  let shippingAvailableMethods;
34
33
  let availableAddressTypes;
35
34
  let selectedPayment;
@@ -112,7 +111,6 @@ newShop.Order = function(orderData){
112
111
  simulateWithoutShipping = orderData.simulateWithoutShipping;
113
112
  externalPayment = orderData.externalPayment;
114
113
  selectedShippingMethod = orderData.selectedShippingMethod;
115
- simulatedShippingMethod = orderData.simulatedShippingMethod || {};
116
114
  shippingAvailableMethods = orderData.shippingAvailableMethods;
117
115
  availableAddressTypes = orderData.availableAddressTypes;
118
116
  errorResponseInfo = orderData.errorResponseInfo;
@@ -267,7 +265,6 @@ newShop.Order = function(orderData){
267
265
  order.simulateWithoutShipping = simulateWithoutShipping;
268
266
  order.externalPayment = externalPayment;
269
267
  order.selectedShippingMethod = selectedShippingMethod;
270
- order.simulatedShippingMethod = simulatedShippingMethod || {};
271
268
  order.shippingAvailableMethods = shippingAvailableMethods;
272
269
  order.availableAddressTypes = availableAddressTypes;
273
270
  order.errorResponseInfo = errorResponseInfo;
@@ -474,14 +471,6 @@ newShop.Order = function(orderData){
474
471
  selectedShippingMethod = _selectedShippingMethod;
475
472
  }
476
473
  },
477
- simulatedShippingMethod: {
478
- get: function() {
479
- return simulatedShippingMethod;
480
- },
481
- set: function(_simulatedShippingMethod) {
482
- simulatedShippingMethod = _simulatedShippingMethod;
483
- }
484
- },
485
474
  shippingAvailableMethods: {
486
475
  get: function() {
487
476
  return shippingAvailableMethods;
@@ -1,11 +1,13 @@
1
1
  import $ from '@nuskin/nuskinjquery';
2
2
  import {Agelocme, CartService, ShippingAddress, ShopContextService, OrderManager, SalesOrder,
3
- PickupUtil, Product, ProductService, ExternalPaymentService, ProcessorCode} from "../shop.js";
3
+ 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 { storage } from "@nuskin/ns-util";
8
+ import PickupUtil from '../shipping/pickupUtil';
9
+ import {Order} from '@nuskin/order-model';
10
+ import {storage} from "@nuskin/ns-util";
9
11
 
10
12
  let splitLineItems = [];
11
13
  const utmInfo = storage.getItem(storage.metadata.UTM_INFO) || {};
@@ -169,12 +171,16 @@ const getDefaultShipCode = (osmc) => {
169
171
  if (useShipMethodsApi) {
170
172
  const csDefaultCode = getCachedConfigField('defaultShipMethod');
171
173
  const shipMethods = PickupUtil.getStoredShipMethods();
172
- const firstSm = shipMethods.length > 0 ? shipMethods[0].Code : '';
173
- const defaultShipMethod = shipMethods.find((sm) => sm.Code === osmc);
174
- if (!defaultShipMethod) {
175
- defaultCode = shipMethods.find((sm) => sm.Code === csDefaultCode) ? csDefaultCode : firstSm;
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
+ }
176
182
  } else {
177
- defaultCode = defaultShipMethod.Code;
183
+ defaultCode = csDefaultCode;
178
184
  }
179
185
  }
180
186
 
@@ -649,6 +655,10 @@ const syncProductItems = async (order, sapProducts, adr, includeSapItems) => {
649
655
  label = custom.Value;
650
656
  } else if (custom.Key === 'SUB_PRICE') {
651
657
  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;
652
662
  }
653
663
  });
654
664
  if (code != null || name !== null || label != null) {
@@ -1119,6 +1129,18 @@ const populateSalesOrder = (action, adr) => {
1119
1129
  return salesOrder;
1120
1130
  };
1121
1131
 
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
+
1122
1144
  /**
1123
1145
  * Maps Sales order detail object to the order object
1124
1146
  * @param {Object} salesOrderDetail
@@ -1138,14 +1160,12 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1138
1160
  order.shippingPayWithPoints = salesOrderDetail.Custom.map(item => item.Key).indexOf('ZZUSE_PTS') > -1;
1139
1161
  }
1140
1162
 
1163
+ await syncProductItems(order, salesOrderDetail.LineItemDetails, order.adr ? adr : null);
1164
+
1141
1165
  const useShipMethodsApi = getCachedConfigField('useShipMethodsApi');
1142
1166
  if (useShipMethodsApi || salesOrderDetail.ShippingAvailableMethods && salesOrderDetail.ShippingAvailableMethods.length > 0) {
1143
- const shipMethods = useShipMethodsApi ? await PickupUtil.getShipMethods() : salesOrderDetail.ShippingAvailableMethods;
1167
+ const shipMethods = await getShipMethods(salesOrderDetail, order.orderType);
1144
1168
  order.shippingAvailableMethods = sortShippingAvailableMethods(shipMethods);
1145
- order.simulatedShippingMethod =
1146
- order.shippingAvailableMethods.find(
1147
- (sam) => sam.Code === salesOrderDetail.Shipping.ShippingMethod.Code
1148
- ) || order.shippingAvailableMethods[0];
1149
1169
 
1150
1170
  setShippingAvailableMethodsPickupInfo(order.shippingAvailableMethods);
1151
1171
  setSelectedShipMethod(order, salesOrderDetail.Shipping.ShippingMethod);
@@ -1165,7 +1185,6 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1165
1185
  syncShipping(salesOrderDetail.Shipping, order);
1166
1186
  }
1167
1187
 
1168
- await syncProductItems(order, salesOrderDetail.LineItemDetails, order.adr ? adr : null);
1169
1188
  syncOrderTotals(salesOrderDetail.OrderTotals, order.orderTotals);
1170
1189
  syncPayment(salesOrderDetail.Payment, order.selectedPayment);
1171
1190
  OrderManager.saveOrders();
@@ -5,6 +5,7 @@ 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';
8
9
 
9
10
  const ORDER_STORAGE_KEY = storage.metadata.ORDER_STORAGE_KEY,
10
11
  ORDER_PREFS_STORAGE_KEY = storage.metadata.ORDER_PREFS_STORAGE_KEY,
@@ -73,6 +74,14 @@ const _initOrder = () => {
73
74
  result.selectedAddress = orderPreferences.selectedAddress;
74
75
  }
75
76
  }
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
+ }
76
85
 
77
86
  return new Order(result);
78
87
  };
@@ -1,7 +1,6 @@
1
1
  import {getCachedConfiguration} from '@nuskin/configuration-sdk';
2
- import {Order} from '@nuskin/order-model';
3
2
  import {RunConfigService} from '@nuskin/ns-util';
4
- import {OrderManager, CartService, OrderType, OrderAdapter} from '../shop';
3
+ import {OrderManager, CartService, OrderType} from '../shop';
5
4
  import axios from 'axios';
6
5
 
7
6
  let PickupUtil = function() {
@@ -187,18 +186,15 @@ let PickupUtil = function() {
187
186
  const storedShipData = getShipToData(storedPayload.order);
188
187
  same = payload.country === storedPayload.country &&
189
188
  payload.dangerousGoods === storedPayload.dangerousGoods &&
190
- payload.orderValue === storedPayload.orderValue &&
191
189
  shipData.country === storedShipData.country &&
192
190
  shipData.postalCode === storedShipData.postalCode &&
193
191
  shipData.line1 === storedShipData.line1 &&
194
- shipData.line2 === storedShipData.line2 &&
195
192
  shipData.city === storedShipData.city
196
193
  }
197
194
  return same
198
195
  }
199
196
 
200
- function loadShipMethods() {
201
- const order = Order.fromSalesOrderRequest(OrderAdapter.populateSalesOrder('SIMULATE'));
197
+ function loadShipMethods(order, orderType) {
202
198
  const {metapackMarket} = getCachedConfiguration('Checkout');
203
199
 
204
200
  if (metapackMarket) {
@@ -206,7 +202,8 @@ let PickupUtil = function() {
206
202
  const payload = {
207
203
  order,
208
204
  orderValue: getOrderValue(),
209
- dangerousGoods: CartService.hasDangerousGoods(),
205
+ dangerousGoods: CartService.hasDangerousGoods(orderType),
206
+ weight: CartService.getCartWeight(orderType),
210
207
  language: runConfig.language,
211
208
  country: runConfig.country
212
209
  };