@nuskin/cs-product-lib 1.0.6 → 1.0.8
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 +17 -13
- package/src/formatKit.js +13 -6
- package/src/formatProduct.js +2 -2
- package/src/transformBundle.js +1 -1
package/package.json
CHANGED
package/src/csProduct.js
CHANGED
|
@@ -156,33 +156,37 @@ const csProduct = (props) => {
|
|
|
156
156
|
|
|
157
157
|
const formatProductWithSchema = (products = []) => {
|
|
158
158
|
return products?.map((product) => {
|
|
159
|
-
const
|
|
160
|
-
|
|
159
|
+
const formattedProduct = formatProduct(product, homeUrl)
|
|
160
|
+
formattedProduct.variants = formattedProduct?.variants?.map(
|
|
161
161
|
(variant) => formatVariant(variant)
|
|
162
162
|
)
|
|
163
|
-
return
|
|
163
|
+
return formattedProduct
|
|
164
164
|
})
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
const formatBundleWithSchema = (bundles = []) => {
|
|
168
168
|
return bundles?.map((bundle) => {
|
|
169
|
-
const
|
|
169
|
+
const formattedBundle = transformBundle(bundle, homeUrl)
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
formattedBundle.requiredProducts = formattedBundle?.requiredProducts?.map(
|
|
172
172
|
({product, quantity}) => {
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
if (product) {
|
|
174
|
+
const [formattedProduct] = formatProductWithSchema([product])
|
|
175
|
+
return {product : formattedProduct, quantity}
|
|
176
|
+
} else {
|
|
177
|
+
return {}
|
|
178
|
+
}
|
|
175
179
|
}
|
|
176
180
|
)
|
|
177
181
|
|
|
178
|
-
|
|
182
|
+
formattedBundle.optionalProducts = formattedBundle?.optionalProducts?.map(
|
|
179
183
|
({product, quantity}) => {
|
|
180
|
-
const [
|
|
181
|
-
return {product :
|
|
184
|
+
const [formattedProduct] = formatProductWithSchema([product])
|
|
185
|
+
return {product : formattedProduct, quantity}
|
|
182
186
|
}
|
|
183
187
|
)
|
|
184
188
|
|
|
185
|
-
return
|
|
189
|
+
return formattedBundle
|
|
186
190
|
})
|
|
187
191
|
}
|
|
188
192
|
|
|
@@ -419,10 +423,10 @@ const csProduct = (props) => {
|
|
|
419
423
|
|
|
420
424
|
const getProductTranslations = async (locale) => {
|
|
421
425
|
const translations = await getTranslations(locale)
|
|
422
|
-
const
|
|
426
|
+
const formattedTranslations = translations.map((translate) =>
|
|
423
427
|
formatTranslations(translate)
|
|
424
428
|
)
|
|
425
|
-
return
|
|
429
|
+
return formattedTranslations
|
|
426
430
|
}
|
|
427
431
|
|
|
428
432
|
const publishedProducts = async ({ locale, skip = 0, limit = 50 } = {}) => {
|
package/src/formatKit.js
CHANGED
|
@@ -91,6 +91,9 @@ const parseBundleAvailableQuantity = (product) => {
|
|
|
91
91
|
const parseKit = (product, market) => {
|
|
92
92
|
const kits = {}
|
|
93
93
|
const [properties] = product || []
|
|
94
|
+
kits.id = properties?.id
|
|
95
|
+
kits.uid = properties?.uid
|
|
96
|
+
kits.title = properties?.title
|
|
94
97
|
kits.description = properties?.description
|
|
95
98
|
kits.availableChannels = properties.availableChannels
|
|
96
99
|
kits.chargeShipping = properties.chargeShipping === 'true'
|
|
@@ -131,14 +134,18 @@ const parseKit = (product, market) => {
|
|
|
131
134
|
kits.type = 'bundle'
|
|
132
135
|
kits.availableQuantity = parseBundleAvailableQuantity(properties)
|
|
133
136
|
for (const kit of properties?.requiredProducts || []) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
if (kit.product) {
|
|
138
|
+
const kitProduct = formatKit(kit?.product, market)
|
|
139
|
+
kitProduct.id = kit.product.id
|
|
140
|
+
kitProducts.push({product: kitProduct, quantity: kit?.quantity || 0, isMandatory:true})
|
|
141
|
+
}
|
|
137
142
|
}
|
|
138
143
|
for (const kit of properties?.optionalProducts || []) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
if (kit.product) {
|
|
145
|
+
const kitProduct = formatKit(kit?.product, market)
|
|
146
|
+
kitProduct.id = kit.product.id
|
|
147
|
+
kitProducts.push({product: kitProduct, quantity: kit?.quantity || 0, isMandatory:false})
|
|
148
|
+
}
|
|
142
149
|
}
|
|
143
150
|
}
|
|
144
151
|
kits.kitProducts = kitProducts
|
package/src/formatProduct.js
CHANGED
|
@@ -4,7 +4,7 @@ const { formatKit } = require('./formatKit')
|
|
|
4
4
|
|
|
5
5
|
/* istanbul ignore next */
|
|
6
6
|
const formatProduct = (parent, homeUrl) => {
|
|
7
|
-
const
|
|
7
|
+
const formattedProduct = {
|
|
8
8
|
// Each value is a function with a parameter 'parent' that is the current instance of a Product
|
|
9
9
|
// ContentStack references need to be queried separately (ie: variants)
|
|
10
10
|
id: parent.uid,
|
|
@@ -76,7 +76,7 @@ const formatProduct = (parent, homeUrl) => {
|
|
|
76
76
|
upSellProductIds: helpers?.mapUpSellProductIds(parent),
|
|
77
77
|
crossProductIds: helpers?.mapCrossProductIds(parent)
|
|
78
78
|
}
|
|
79
|
-
return formatKit(
|
|
79
|
+
return formatKit(formattedProduct)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
module.exports = {
|
package/src/transformBundle.js
CHANGED
|
@@ -4,7 +4,7 @@ const helpers = require('./helpers')
|
|
|
4
4
|
const transformBundle = (parent, homeUrl) => ({
|
|
5
5
|
id: parent.bundle_id,
|
|
6
6
|
uid: parent.uid,
|
|
7
|
-
title: parent.
|
|
7
|
+
title: parent.title,
|
|
8
8
|
type: parent.type,
|
|
9
9
|
requiredProducts: parent.required_products?.map((r) => ({
|
|
10
10
|
product: r?.product?.[0],
|