@nuskin/ns-shop 7.7.0-mdigi-6056.5 → 7.7.0-pa-87.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.7.0-mdigi-6056.5",
3
+ "version": "7.7.0-pa-87.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": {
@@ -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",
package/src/cart/cart.js CHANGED
@@ -1414,11 +1414,7 @@ export default function Cart(cartData) {
1414
1414
  'name': flatItem.title,
1415
1415
  'id': flatItem.sku,
1416
1416
  'price': flatItem.price,
1417
- 'quantity': Math.abs(diffQty),
1418
- 'taxonomy': flatItem.taxonomy,
1419
- 'sales_price': flatItem.salesPrice,
1420
- 'unit_price': flatItem.unitPrice,
1421
- 'product_image_url': flatItem.product_image_url
1417
+ 'quantity': Math.abs(diffQty)
1422
1418
  });
1423
1419
 
1424
1420
  function getCartInfo(options) {
@@ -293,30 +293,6 @@ export default function CartItem(cartItemData) {
293
293
  return this.product.marketAttributes;
294
294
  }
295
295
 
296
- this.unitPrice = function () {
297
- if (AccountManager.isCustomer() || AccountManager.isPreferredCustomer()) {
298
- return this.product.priceMap.RTL;
299
- } else if (AccountManager.isDistributor()) {
300
- return this.product.priceMap.WHL;
301
- }
302
- }
303
-
304
- this.salesPrice = function () {
305
- if (AccountManager.isCustomer() || AccountManager.isPreferredCustomer()) {
306
- if (this.product.priceType.WADR) {
307
- return this.product.priceMap.WADR;
308
- } else {
309
- return this.product.priceMap.RTL;
310
- }
311
- } else if (AccountManager.isDistributor()) {
312
- if (this.product.priceType.WADR) {
313
- return this.product.priceMap.WADW;
314
- } else {
315
- return this.product.priceMap.WHL;
316
- }
317
- }
318
- }
319
-
320
296
  this.toFlatJson = function() {
321
297
  let retVal = {};
322
298
 
@@ -376,10 +352,6 @@ export default function CartItem(cartItemData) {
376
352
  retVal.size = this.product.size;
377
353
  retVal.variants = this.product.variants;
378
354
  retVal.marketAttributes = this.product.marketAttributes;
379
- retVal.product_image_url = this.product.fullImage;
380
- retVal.taxonomy = this.product.title ? this.product.title.split(' ')[0] : '';
381
- retVal.salesPrice = AccountManager.isLoggedIn()? this.salesPrice() : null;
382
- retVal.unitPrice = AccountManager.isLoggedIn()? this.unitPrice() : null;
383
355
 
384
356
  return retVal;
385
357
  };
@@ -35,6 +35,7 @@ export default {
35
35
  hasEventItems,
36
36
  hasPreviewItems,
37
37
  hasDangerousGoods,
38
+ getCartWeight,
38
39
  getItemCnt,
39
40
  addProductToCart,
40
41
  addSkuToCart,
@@ -307,6 +308,14 @@ function hasDangerousGoods(options = {cartItems: true}) {
307
308
  return retVal;
308
309
  }
309
310
 
311
+ function getCartWeight() {
312
+ let retVal = 0.0;
313
+ _getCart().getItems({cartItems: true}).forEach((item) => {
314
+ retVal += item.qty * (item.product.grossWeight || 0.0);
315
+ });
316
+ return retVal;
317
+ }
318
+
310
319
  function getItemCnt(options) {
311
320
  return _getCart().getItemCnt(options);
312
321
  }
@@ -820,6 +829,8 @@ function syncCartItemToSapItem(sapItemKey, cartItemKey = null) {
820
829
  cartItem.redeem = sapItem.redeem;
821
830
  cartItem.qtyRedeemWithPoints = sapItem.qtyRedeemWithPoints;
822
831
  cartItem.product.subPriceFlag = sapItem.product.subPriceFlag;
832
+ cartItem.product.grossWeight = sapItem.product.grossWeight;
833
+ cartItem.product.weightUnit = sapItem.product.weightUnit;
823
834
  cart.addCartItem(cartItem, true);
824
835
  setCart(cart, false);
825
836
  }
@@ -115,7 +115,32 @@ const convertPricing = (pricing, productData) => {
115
115
  }
116
116
  }
117
117
 
118
- const createDataFromSkuSearch = (searchData, options) => {
118
+ const checkMaxQuantity = async (status) => {
119
+ const {Basic: basicCfg} = await getConfiguration(['Basic'])
120
+ let configMaxes
121
+
122
+ try {
123
+ configMaxes = basicCfg.skuMaxQty
124
+ .map((cm) => JSON.parse(cm))
125
+ .reduce((map, cmItem) => {
126
+ map[cmItem.sku] = cmItem.maxQty;
127
+ return map;
128
+ }, {});
129
+ } catch (err) {
130
+ console.log('Error parsing skuMaxQty from config', err);
131
+ configMaxes = {};
132
+ }
133
+ status.maxQuantity = status.availableQuantity < 999 ? status.availableQuantity : 999;
134
+ if (configMaxes && Object.keys(configMaxes).length > 0) {
135
+ if (Object.hasOwn(configMaxes, status.sku)) {
136
+ if (configMaxes[status.sku] < status.availableQuantity) {
137
+ status.maxQuantity = configMaxes[status.sku];
138
+ }
139
+ }
140
+ }
141
+ }
142
+
143
+ const createDataFromSkuSearch = async (searchData, options) => {
119
144
  if (!searchData) {
120
145
  return new Product();
121
146
  }
@@ -185,6 +210,7 @@ const createDataFromSkuSearch = (searchData, options) => {
185
210
  orderType: orderTypes, // searchData.channels.map((channel) => channel.toLowerCase()),
186
211
  childSkus: null // ???
187
212
  };
213
+ await checkMaxQuantity(status);
188
214
  convertPricing(pricing, status);
189
215
  product.addPricingFromStatus(status);
190
216
  }
@@ -199,7 +225,7 @@ const createDataFromSkuSearch = (searchData, options) => {
199
225
 
200
226
  const handleDetailResponse = async (responseData, options) => {
201
227
  let retVal = {success: true},
202
- dataForProduct = createDataFromSkuSearch(responseData, options);
228
+ dataForProduct = await createDataFromSkuSearch(responseData, options);
203
229
 
204
230
  if (dataForProduct.sku) {
205
231
  retVal.product = new Product(dataForProduct);
@@ -268,7 +294,7 @@ const getProductBySku = async (options) => {
268
294
  const getProductData = async (options) => {
269
295
  const data = await getProductDetail(options);
270
296
 
271
- return createDataFromSkuSearch(data, options);
297
+ return await createDataFromSkuSearch(data, options);
272
298
  }
273
299
 
274
300
  export {
@@ -395,7 +395,7 @@ function _assembleChildSkus(requestData, options) {
395
395
  if (personalOffer !== null) {
396
396
  personalOffer = JSON.parse(personalOffer);
397
397
  productWithVariant = personalOffer.products.filter((sku) =>
398
- sku.type === 'bundle' && sku.variantSelected !== null && sku.sku === productSku
398
+ sku.type.toLowerCase() === 'bundle' && sku.variantSelected !== null && sku.sku === productSku
399
399
  )
400
400
  }
401
401
 
@@ -411,7 +411,7 @@ function _assembleChildSkus(requestData, options) {
411
411
  }
412
412
  if (personalOffer != null && selectedVariants && cs.skuId != selectedVariants[cs.productId] && (cs.type !== "BUNDLE" && cs.type !== "OPTIONAL")) return null
413
413
  const childSku =
414
- (personalOffer != null && selectedVariants && selectedVariants[cs.productId] && config.MySite_graphql_active)
414
+ (personalOffer != null && selectedVariants && selectedVariants[cs.productId] && config && config.MySite_graphql_active)
415
415
  ? {
416
416
  productId: cs.productId,
417
417
  skuId: selectedVariants[cs.productId],
@@ -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,12 +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 pickupUtil from '../shipping/pickupUtil';
9
- 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";
10
11
 
11
12
  let splitLineItems = [];
12
13
  const utmInfo = storage.getItem(storage.metadata.UTM_INFO) || {};
@@ -170,12 +171,16 @@ const getDefaultShipCode = (osmc) => {
170
171
  if (useShipMethodsApi) {
171
172
  const csDefaultCode = getCachedConfigField('defaultShipMethod');
172
173
  const shipMethods = PickupUtil.getStoredShipMethods();
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;
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
+ }
177
182
  } else {
178
- defaultCode = defaultShipMethod.Code;
183
+ defaultCode = csDefaultCode;
179
184
  }
180
185
  }
181
186
 
@@ -501,7 +506,7 @@ const populateCategory = (salesOrder) => {
501
506
  } else if (utmMedium && utmMedium.toLowerCase().includes('paidsearch')) {
502
507
  salesOrder.Category = 'PAIDSEARCH';
503
508
  } else if (utmMedium && utmMedium.toLowerCase().includes('paidsocial')) {
504
- salesOrder.Category = 'PAIDAD';
509
+ salesOrder.Category = 'PAIDAD';
505
510
  } else {
506
511
  salesOrder.Category = 'WEB';
507
512
  }
@@ -650,6 +655,10 @@ const syncProductItems = async (order, sapProducts, adr, includeSapItems) => {
650
655
  label = custom.Value;
651
656
  } else if (custom.Key === 'SUB_PRICE') {
652
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;
653
662
  }
654
663
  });
655
664
  if (code != null || name !== null || label != null) {
@@ -1120,6 +1129,18 @@ const populateSalesOrder = (action, adr) => {
1120
1129
  return salesOrder;
1121
1130
  };
1122
1131
 
1132
+ const getShipMethods = async (salesOrderDetail) => {
1133
+ let shipMethods;
1134
+ const useShipMethodsApi = getCachedConfigField('useShipMethodsApi');
1135
+ if (useShipMethodsApi) {
1136
+ await PickupUtil.loadShipMethods(Order.fromSalesOrderRequest(populateSalesOrder('SIMULATE')));
1137
+ shipMethods = await PickupUtil.getShipMethods();
1138
+ } else {
1139
+ shipMethods = salesOrderDetail.ShippingAvailableMethods
1140
+ }
1141
+ return shipMethods
1142
+ }
1143
+
1123
1144
  /**
1124
1145
  * Maps Sales order detail object to the order object
1125
1146
  * @param {Object} salesOrderDetail
@@ -1139,14 +1160,12 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1139
1160
  order.shippingPayWithPoints = salesOrderDetail.Custom.map(item => item.Key).indexOf('ZZUSE_PTS') > -1;
1140
1161
  }
1141
1162
 
1163
+ await syncProductItems(order, salesOrderDetail.LineItemDetails, order.adr ? adr : null);
1164
+
1142
1165
  const useShipMethodsApi = getCachedConfigField('useShipMethodsApi');
1143
1166
  if (useShipMethodsApi || salesOrderDetail.ShippingAvailableMethods && salesOrderDetail.ShippingAvailableMethods.length > 0) {
1144
- const shipMethods = useShipMethodsApi ? await pickupUtil.getShipMethods() : salesOrderDetail.ShippingAvailableMethods;
1167
+ const shipMethods = await getShipMethods(salesOrderDetail);
1145
1168
  order.shippingAvailableMethods = sortShippingAvailableMethods(shipMethods);
1146
- order.simulatedShippingMethod =
1147
- order.shippingAvailableMethods.find(
1148
- (sam) => sam.Code === salesOrderDetail.Shipping.ShippingMethod.Code
1149
- ) || order.shippingAvailableMethods[0];
1150
1169
 
1151
1170
  setShippingAvailableMethodsPickupInfo(order.shippingAvailableMethods);
1152
1171
  setSelectedShipMethod(order, salesOrderDetail.Shipping.ShippingMethod);
@@ -1156,7 +1175,7 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1156
1175
  let oldPup = null;
1157
1176
  if (!useShipMethodsApi) oldPup = salesOrderDetail.Custom;
1158
1177
  let newPup = null;
1159
- if (useShipMethodsApi) newPup = await pickupUtil.getPickupPoints();
1178
+ if (useShipMethodsApi) newPup = await PickupUtil.getPickupPoints();
1160
1179
  setPickupPoints(oldPup, newPup, order);
1161
1180
  }
1162
1181
  }
@@ -1166,7 +1185,6 @@ const toOrder = async (salesOrderDetail, adr, createResponse) => {
1166
1185
  syncShipping(salesOrderDetail.Shipping, order);
1167
1186
  }
1168
1187
 
1169
- await syncProductItems(order, salesOrderDetail.LineItemDetails, order.adr ? adr : null);
1170
1188
  syncOrderTotals(salesOrderDetail.OrderTotals, order.orderTotals);
1171
1189
  syncPayment(salesOrderDetail.Payment, order.selectedPayment);
1172
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() {
@@ -197,8 +196,7 @@ let PickupUtil = function() {
197
196
  return same
198
197
  }
199
198
 
200
- function loadShipMethods() {
201
- const order = Order.fromSalesOrderRequest(OrderAdapter.populateSalesOrder('SIMULATE'));
199
+ function loadShipMethods(order) {
202
200
  const {metapackMarket} = getCachedConfiguration('Checkout');
203
201
 
204
202
  if (metapackMarket) {
@@ -207,6 +205,7 @@ let PickupUtil = function() {
207
205
  order,
208
206
  orderValue: getOrderValue(),
209
207
  dangerousGoods: CartService.hasDangerousGoods(),
208
+ weight: CartService.getCartWeight(),
210
209
  language: runConfig.language,
211
210
  country: runConfig.country
212
211
  };