@nuskin/ns-shop 7.2.1-mdigi-2049.2 → 7.2.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.2.1-mdigi-2049.2",
3
+ "version": "7.2.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": {
@@ -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;
@@ -110,6 +111,7 @@ newShop.Order = function(orderData){
110
111
  simulateWithoutShipping = orderData.simulateWithoutShipping;
111
112
  externalPayment = orderData.externalPayment;
112
113
  selectedShippingMethod = orderData.selectedShippingMethod;
114
+ simulatedShippingMethod = orderData.simulatedShippingMethod || {};
113
115
  shippingAvailableMethods = orderData.shippingAvailableMethods;
114
116
  availableAddressTypes = orderData.availableAddressTypes;
115
117
  errorResponseInfo = orderData.errorResponseInfo;
@@ -263,6 +265,7 @@ newShop.Order = function(orderData){
263
265
  order.simulateWithoutShipping = simulateWithoutShipping;
264
266
  order.externalPayment = externalPayment;
265
267
  order.selectedShippingMethod = selectedShippingMethod;
268
+ order.simulatedShippingMethod = simulatedShippingMethod || {};
266
269
  order.shippingAvailableMethods = shippingAvailableMethods;
267
270
  order.availableAddressTypes = availableAddressTypes;
268
271
  order.errorResponseInfo = errorResponseInfo;
@@ -468,6 +471,14 @@ newShop.Order = function(orderData){
468
471
  selectedShippingMethod = _selectedShippingMethod;
469
472
  }
470
473
  },
474
+ simulatedShippingMethod: {
475
+ get: function() {
476
+ return simulatedShippingMethod;
477
+ },
478
+ set: function(_simulatedShippingMethod) {
479
+ simulatedShippingMethod = _simulatedShippingMethod;
480
+ }
481
+ },
471
482
  shippingAvailableMethods: {
472
483
  get: function() {
473
484
  return shippingAvailableMethods;
@@ -164,14 +164,20 @@ const populateAttribution = (salesOrder) => {
164
164
  }
165
165
  }
166
166
 
167
- const getDefaultShipCode = () => {
167
+ const getDefaultShipCode = (osmc) => {
168
168
  let defaultCode = '';
169
+ osmc = osmc === 'CI' ? '' : osmc;
169
170
  const useShipMethodsApi = getCachedConfigField('useShipMethodsApi')
170
171
  if (useShipMethodsApi) {
171
172
  const csDefaultCode = getCachedConfigField('defaultShipMethod');
172
173
  const shipMethods = PickupUtil.getStoredShipMethods();
173
174
  const firstSm = shipMethods.length > 0 ? shipMethods[0].Code : '';
174
- defaultCode = shipMethods.find((sm) => sm.Code === csDefaultCode) ? csDefaultCode : firstSm;
175
+ const defaultShipMethod = shipMethods.find((sm) => sm.Code === osmc);
176
+ if (!defaultShipMethod) {
177
+ defaultCode = shipMethods.find((sm) => sm.Code === csDefaultCode) ? csDefaultCode : firstSm;
178
+ } else {
179
+ defaultCode = defaultShipMethod.Code;
180
+ }
175
181
  }
176
182
 
177
183
  return defaultCode;
@@ -179,9 +185,9 @@ const getDefaultShipCode = () => {
179
185
 
180
186
  const populateShipping = (order, salesOrder) => {
181
187
  const user = UserService.getUser();
182
- const defaultCode = getDefaultShipCode();
183
- const method = order.selectedShippingMethod;
184
- const code = method ? method.Code : defaultCode;
188
+ const orderShipMethod = order.selectedShippingMethod;
189
+ const orderShipMethodCode = orderShipMethod ? orderShipMethod.Code : null;
190
+ const code = getDefaultShipCode(orderShipMethodCode);
185
191
 
186
192
  //code = (util.countryCode === 'ZA') ? (order.selectedAddress.addressType == "home" ? "ZH" : "ST") : code;
187
193
 
@@ -323,8 +329,8 @@ const populateShipping = (order, salesOrder) => {
323
329
  salesOrder.Shipping.ShippingParty.push(billTo);
324
330
  }
325
331
 
326
- if (method && method.PickUpLocation) {
327
- salesOrder.Shipping.ShippingMethod.PickUpLocation = method.PickUpLocation;
332
+ if (orderShipMethod && orderShipMethod.PickUpLocation) {
333
+ salesOrder.Shipping.ShippingMethod.PickUpLocation = orderShipMethod.PickUpLocation;
328
334
  }
329
335
  if (order.selectedDeliveryTimeSlot) {
330
336
  salesOrder.timeSlotId = order.selectedDeliveryTimeSlot.id;
@@ -1138,6 +1144,11 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1138
1144
  if (useShipMethodsApi || salesOrderDetail.ShippingAvailableMethods && salesOrderDetail.ShippingAvailableMethods.length > 0) {
1139
1145
  const shipMethods = useShipMethodsApi ? await pickupUtil.getShipMethods() : salesOrderDetail.ShippingAvailableMethods;
1140
1146
  order.shippingAvailableMethods = sortShippingAvailableMethods(shipMethods);
1147
+ order.simulatedShippingMethod =
1148
+ order.shippingAvailableMethods.find(
1149
+ (sam) => sam.Code === salesOrderDetail.Shipping.ShippingMethod.Code
1150
+ ) || order.shippingAvailableMethods[0];
1151
+
1141
1152
  setShippingAvailableMethodsPickupInfo(order.shippingAvailableMethods);
1142
1153
  setSelectedShipMethod(order, salesOrderDetail.Shipping.ShippingMethod);
1143
1154
  // When an order or ADR is created. The response from the create call is missing the list of pickup locations
@@ -5,7 +5,7 @@ import {OrderManager, CartService, OrderType, OrderAdapter} from '../shop';
5
5
  import axios from 'axios';
6
6
 
7
7
  const SHIP_METHODS = 'shipMethods';
8
- const Pick_UP_POINTS = 'pickUpPoints';
8
+ const PICK_UP_POINTS = 'pickUpPoints';
9
9
 
10
10
  let PickupUtil = function() {
11
11
  'use strict';
@@ -192,11 +192,11 @@ let PickupUtil = function() {
192
192
  }
193
193
  ).then((results) => {
194
194
  sessionStorage.setItem(SHIP_METHODS, JSON.stringify(results.data.shipMethods))
195
- sessionStorage.setItem(Pick_UP_POINTS, JSON.stringify(results.data.pickupPoints))
195
+ sessionStorage.setItem(PICK_UP_POINTS, JSON.stringify(results.data.pickupPoints))
196
196
  }).catch((err) => {
197
197
  console.log(err);
198
198
  sessionStorage.setItem(SHIP_METHODS, JSON.stringify([]));
199
- sessionStorage.setItem(Pick_UP_POINTS, JSON.stringify([]));
199
+ sessionStorage.setItem(PICK_UP_POINTS, JSON.stringify([]));
200
200
  });
201
201
  }
202
202
  }
@@ -204,7 +204,8 @@ let PickupUtil = function() {
204
204
  // if the calling code knows that loadShipMethods has finished then this
205
205
  // function can be called directly if the calling function is not async.
206
206
  function getStoredShipMethods() {
207
- return JSON.parse((sessionStorage.getItem(SHIP_METHODS) || '[]'));
207
+ const shipMethods = sessionStorage.getItem(SHIP_METHODS);
208
+ return shipMethods ? JSON.parse(shipMethods) : [];
208
209
  }
209
210
 
210
211
  async function getShipMethods() {
@@ -216,7 +217,8 @@ let PickupUtil = function() {
216
217
  async function getPickupPoints() {
217
218
  await promise;
218
219
 
219
- return JSON.parse(sessionStorage.getItem(Pick_UP_POINTS) || []);
220
+ const pups = sessionStorage.getItem(PICK_UP_POINTS);
221
+ return pups ? JSON.parse(pups) : [];
220
222
  }
221
223
 
222
224
  return {