@nuskin/ns-shop 7.6.3-mdigi-4997.1 → 7.6.3

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.6.3-mdigi-4997.1",
3
+ "version": "7.6.3",
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": {
@@ -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.toLowerCase() === 'bundle' && sku.variantSelected !== null && sku.sku === productSku
398
+ sku.type === 'bundle' && sku.variantSelected !== null && sku.sku === productSku
399
399
  )
400
400
  }
401
401
 
@@ -411,18 +411,18 @@ 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 && config.MySite_graphql_active)
415
- ? {
416
- productId: cs.productId,
417
- skuId: selectedVariants[cs.productId],
418
- type: cs.type,
419
- availableChannels: cs.availableChannels
420
- } : {
421
- productId: cs.productId,
422
- skuId: cs.skuId,
423
- type: cs.type,
424
- availableChannels: cs.availableChannels
425
- }
414
+ (personalOffer != null && selectedVariants && selectedVariants[cs.productId] && config.MySite_graphql_active)
415
+ ? {
416
+ productId: cs.productId,
417
+ skuId: selectedVariants[cs.productId],
418
+ type: cs.type,
419
+ availableChannels: cs.availableChannels
420
+ } : {
421
+ productId: cs.productId,
422
+ skuId: cs.skuId,
423
+ type: cs.type,
424
+ availableChannels: cs.availableChannels
425
+ }
426
426
  if (cs.inventory) {
427
427
  childSku.skuQuantity = cs.skuQuantity;
428
428
  childSku.backOrdered = cs.inventory.backOrdered;