@nuskin/cs-product-lib 1.7.2-status-key.1 → 1.7.3-bundleonly-members.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 +1 -1
- package/src/csProduct.js +8 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuskin/cs-product-lib",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3-bundleonly-members.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
|
@@ -108,7 +108,7 @@ const csProduct = (props) => {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
const removeInvalidVariants = async (products = [], locale, translations) => {
|
|
111
|
+
const removeInvalidVariants = async (products = [], locale, translations, keepBundleOnly = false) => {
|
|
112
112
|
const validSkus = []
|
|
113
113
|
for (const product of products) {
|
|
114
114
|
for (const variant of product?.variants || []) {
|
|
@@ -154,11 +154,13 @@ const csProduct = (props) => {
|
|
|
154
154
|
const bestSkuData = helpers?.getBestSkuData(variant)
|
|
155
155
|
if (bestSkuData.sku) {
|
|
156
156
|
const varStatus = status[bestSkuData.sku]
|
|
157
|
-
|
|
157
|
+
const isBundleOnly =
|
|
158
|
+
bestSkuData?.status_selections?.status === 'bundleOnly'
|
|
159
|
+
if ((varStatus && varStatus.status.retail) || (keepBundleOnly && isBundleOnly)) {
|
|
158
160
|
variant.sap_data.sku_data = [bestSkuData]
|
|
159
161
|
validVariants.push({
|
|
160
162
|
...variant,
|
|
161
|
-
status: varStatus,
|
|
163
|
+
status: varStatus || { status: { retail: 'bundleOnly', wholesale: 'bundleOnly' } },
|
|
162
164
|
backorderQuantity: varStatus?.backordered ? varStatus?.availableQuantity : 0,
|
|
163
165
|
atpQuantity: varStatus?.backordered ? 0 : varStatus?.availableQuantity,
|
|
164
166
|
availableQuantity: varStatus?.availableQuantity,
|
|
@@ -262,7 +264,7 @@ const csProduct = (props) => {
|
|
|
262
264
|
variantSkus.push((skuData || {}).sku)
|
|
263
265
|
kitItem.sku = (skuData || {}).sku
|
|
264
266
|
}
|
|
265
|
-
const products = await getProductsBySku(variantSkus, locale)
|
|
267
|
+
const products = await getProductsBySku(variantSkus, locale, true)
|
|
266
268
|
const requiredProducts = []
|
|
267
269
|
for (let i = 0; i < products?.length; i++) {
|
|
268
270
|
for (const variantSku of variantSkus) {
|
|
@@ -488,7 +490,7 @@ const csProduct = (props) => {
|
|
|
488
490
|
return [{error: {message: products.message, name: products.name, status: errorResponse.status, errors: [`${responseData.error_code}: ${responseData.error_message}`]}}]
|
|
489
491
|
}
|
|
490
492
|
|
|
491
|
-
const getProductsBySku = async (skus, locale) => {
|
|
493
|
+
const getProductsBySku = async (skus, locale, keepBundleOnly = false) => {
|
|
492
494
|
locale = badLocaleMap(locale)
|
|
493
495
|
if (!Array.isArray(skus)) {
|
|
494
496
|
skus = [skus]
|
|
@@ -515,7 +517,7 @@ const csProduct = (props) => {
|
|
|
515
517
|
}
|
|
516
518
|
const translations = await getTranslations(locale)
|
|
517
519
|
await formatKit(products, locale, translations)
|
|
518
|
-
await removeInvalidVariants(products, locale, translations)
|
|
520
|
+
await removeInvalidVariants(products, locale, translations, keepBundleOnly)
|
|
519
521
|
const formattedProducts = formatProductWithSchema(products)
|
|
520
522
|
for (const product of formattedProducts) {
|
|
521
523
|
product.skus = skus
|