@nuskin/cs-product-lib 1.0.19 → 1.0.20-cx12-7271.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/csProduct.js +20 -65
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/cs-product-lib",
3
- "version": "1.0.19",
3
+ "version": "1.0.20-cx12-7271.1",
4
4
  "description": "Library for pulling and parsing product content (and applying business logic) retrieved from Contentstack",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/csProduct.js CHANGED
@@ -344,75 +344,30 @@ const csProduct = (props) => {
344
344
  }
345
345
 
346
346
  const getBundle = async (id, locale) => {
347
- const query = `{ "$or": [{ "bundle_id": { "$in": ["${id}"]}}, { "uid": { "$in": ["${id}"] }}] }`
348
- const bundles = await getEntriesByQuery({
349
- query,
350
- locale,
351
- contentType: BUNDLE_TYPE
352
- })
353
- const translations = await getTranslations(locale)
354
-
355
- for (let b = 0; b < bundles.length; b++) {
356
- for (
357
- let i = 0;
358
- i < (bundles[b].required_products || []).length;
359
- i++
360
- ) {
361
- await removeInvalidVariants(
362
- bundles[b].required_products[i].product,
363
- locale,
364
- translations
365
- )
366
- }
367
- for (
368
- let i = 0;
369
- i < (bundles[b].optional_products || []).length;
370
- i++
371
- ) {
372
- await removeInvalidVariants(
373
- bundles[b].optional_products[i].product,
374
- locale,
375
- translations
376
- )
377
- }
378
- }
379
- return formatKitWithSchema(bundles)?.[0]
347
+ const bundles = await getBundles(id, locale)
348
+ return bundles && bundles[0] ? bundles[0] : null
380
349
  }
381
350
 
382
351
  const getBundles = async (ids, locale) => {
383
- const query = `{ "$or": [{ "bundle_id": { "$in": ${helpers?.arrayString(ids)} }}, { "uid": { "$in": ${helpers?.arrayString(ids)} }}] }`
384
- const bundles = await getEntriesByQuery({
385
- query,
386
- locale,
387
- contentType: BUNDLE_TYPE
388
- })
389
- const translations = await getTranslations(locale)
390
-
391
- for (let b = 0; b < bundles.length; b++) {
392
- for (
393
- let i = 0;
394
- i < (bundles[b].required_products || []).length;
395
- i++
396
- ) {
397
- await removeInvalidVariants(
398
- bundles[b].required_products[i].product,
399
- locale,
400
- translations
401
- )
402
- }
403
- for (
404
- let i = 0;
405
- i < (bundles[b].optional_products || []).length;
406
- i++
407
- ) {
408
- await removeInvalidVariants(
409
- bundles[b].optional_products[i].product,
410
- locale,
411
- translations
412
- )
413
- }
352
+ if (!Array.isArray(ids)) {
353
+ ids = [ids]
354
+ }
355
+ const idString = helpers?.arrayString([ids])
356
+ const query = `{"$or": [
357
+ {"product_bundle":{"$in_query":{"bundle_id":{"$in": ${idString}}}}},
358
+ {"product_bundle":{"$in_query":{"uid":{"$in": ${idString}}}}},
359
+ {"sku_kit":{"$in_query":{"kit_id":{"$in": ${idString}}}}},
360
+ {"sku_kit":{"$in_query":{"uid":{"$in": ${idString}}}}}
361
+ ]}`
362
+ const products = await queryProducts(query, locale)
363
+ if (products.length > 0) {
364
+ const translations = await getTranslations(locale)
365
+ await formatKit(products, locale, translations)
366
+ await removeInvalidVariants(products, locale, translations)
367
+ return formatProductWithSchema(products)
368
+ } else {
369
+ return []
414
370
  }
415
- return formatKitWithSchema(bundles)
416
371
  }
417
372
 
418
373
  const getProductsBySku = async (skus, locale) => {