@nuskin/ns-shop 7.5.3 → 7.5.4-pa-64.2

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.5.3",
3
+ "version": "7.5.4-pa-64.2",
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": {
@@ -4,9 +4,6 @@ import {RunConfigService} from '@nuskin/ns-util';
4
4
  import {OrderManager, CartService, OrderType, OrderAdapter} from '../shop';
5
5
  import axios from 'axios';
6
6
 
7
- const SHIP_METHODS = 'shipMethods';
8
- const PICK_UP_POINTS = 'pickUpPoints';
9
-
10
7
  let PickupUtil = function() {
11
8
  'use strict';
12
9
  const SERVICE_GROUP = 'SERVICE_GROUP',
@@ -168,42 +165,79 @@ let PickupUtil = function() {
168
165
  }
169
166
  }
170
167
 
168
+ function getShipToData(order) {
169
+ const shippingParties = (order && order.shipping && order.shipping.shippingParties) || [];
170
+ const shipTo = shippingParties.find((sp) => sp.type === 'SHIP_TO');
171
+ return shipTo ? {
172
+ country: shipTo.shippingAddress.address.countryCode,
173
+ postalCode: shipTo.shippingAddress.address.postalCode,
174
+ line1: `${shipTo.shippingAddress.address.street1}, ${shipTo.shippingAddress.address.city}`,
175
+ line2: shipTo.shippingAddress.address.street2,
176
+ city: shipTo.shippingAddress.address.city
177
+ } : {};
178
+ }
179
+
180
+ function samePayload(payload) {
181
+ let same = false;
182
+ const shipping = sessionStorage.getItem('shipping');
183
+
184
+ if (shipping) {
185
+ const storedPayload = JSON.parse(shipping).payload;
186
+ const shipData = getShipToData(payload.order);
187
+ const storedShipData = getShipToData(storedPayload.order);
188
+ same = payload.country === storedPayload.country &&
189
+ payload.dangerousGoods === storedPayload.dangerousGoods &&
190
+ payload.orderValue === storedPayload.orderValue &&
191
+ shipData.country === storedShipData.country &&
192
+ shipData.postalCode === storedShipData.postalCode &&
193
+ shipData.line1 === storedShipData.line1 &&
194
+ shipData.line2 === storedShipData.line2 &&
195
+ shipData.city === storedShipData.city
196
+ }
197
+ return same
198
+ }
199
+
171
200
  function loadShipMethods() {
172
201
  const order = Order.fromSalesOrderRequest(OrderAdapter.populateSalesOrder('SIMULATE'));
173
202
  const {metapackMarket} = getCachedConfiguration('Checkout');
174
203
 
175
204
  if (metapackMarket) {
176
205
  const runConfig = RunConfigService.getRunConfig();
177
- promise = axios.post(
178
- getUrl(),
179
- {
180
- order,
181
- orderValue: getOrderValue(),
182
- dangerousGoods: CartService.hasDangerousGoods(),
183
- language: runConfig.language,
184
- country: runConfig.country
185
- },
186
- {
187
- headers: {
188
- 'Content-Type': 'application/json; charset=UTF-8'
206
+ const payload = {
207
+ order,
208
+ orderValue: getOrderValue(),
209
+ dangerousGoods: CartService.hasDangerousGoods(),
210
+ language: runConfig.language,
211
+ country: runConfig.country
212
+ };
213
+ if (!samePayload(payload)) {
214
+ promise = axios.post(
215
+ getUrl(),
216
+ payload,
217
+ {
218
+ headers: {
219
+ 'Content-Type': 'application/json; charset=UTF-8'
220
+ }
189
221
  }
190
- }
191
- ).then((results) => {
192
- sessionStorage.setItem(SHIP_METHODS, JSON.stringify(results.data.shipMethods))
193
- sessionStorage.setItem(PICK_UP_POINTS, JSON.stringify(results.data.pickupPoints))
194
- }).catch((err) => {
195
- console.log(err);
196
- sessionStorage.setItem(SHIP_METHODS, JSON.stringify([]));
197
- sessionStorage.setItem(PICK_UP_POINTS, JSON.stringify([]));
198
- });
222
+ ).then((results) => {
223
+ sessionStorage.setItem('shipping', JSON.stringify({
224
+ payload,
225
+ shipMethods: results.data.shipMethods,
226
+ pickUpPoints: results.data.pickupPoints
227
+ }))
228
+ }).catch((err) => {
229
+ console.log(err);
230
+ sessionStorage.setItem('shipping', JSON.stringify({payload: {}, shipMethods: [], pickUpPoints: []}));
231
+ });
232
+ }
199
233
  }
200
234
  }
201
235
 
202
236
  // if the calling code knows that loadShipMethods has finished then this
203
237
  // function can be called directly if the calling function is not async.
204
238
  function getStoredShipMethods() {
205
- const shipMethods = sessionStorage.getItem(SHIP_METHODS);
206
- return shipMethods ? JSON.parse(shipMethods) : [];
239
+ const shipping = sessionStorage.getItem('shipping');
240
+ return shipping ? JSON.parse(shipping).shipMethods : [];
207
241
  }
208
242
 
209
243
  async function getShipMethods() {
@@ -215,8 +249,8 @@ let PickupUtil = function() {
215
249
  async function getPickupPoints() {
216
250
  await promise;
217
251
 
218
- const pups = sessionStorage.getItem(PICK_UP_POINTS);
219
- return pups ? JSON.parse(pups) : [];
252
+ const shipping = sessionStorage.getItem('shipping');
253
+ return shipping ? JSON.parse(shipping).pickUpPoints : [];
220
254
  }
221
255
 
222
256
  return {