@nuskin/ns-shop 7.6.2 → 7.6.3-pa-163.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.6.2",
3
+ "version": "7.6.3-pa-163.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": {
@@ -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.configMaxes
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 {