@nuskin/cs-product-lib 1.0.22-pass-name.1 → 1.0.22
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 +100 -41
- package/src/formatCategoryTranslations.js +16 -0
- package/src/formatKit.js +129 -53
- package/src/formatProduct.js +1 -2
- package/src/formatTranslations.js +10 -5
- package/src/formatVariant.js +1 -2
- package/src/transformBundle.js +1 -2
package/package.json
CHANGED
package/src/csProduct.js
CHANGED
|
@@ -7,6 +7,7 @@ const { formatTranslations } = require('./formatTranslations')
|
|
|
7
7
|
const { formatVariant } = require('./formatVariant')
|
|
8
8
|
const { formatProduct } = require('./formatProduct')
|
|
9
9
|
const { transformBundle } = require('./transformBundle')
|
|
10
|
+
const { formatCategoryTranslations } = require('./formatCategoryTranslations')
|
|
10
11
|
|
|
11
12
|
const validateConfig = (props) => {
|
|
12
13
|
if (!props) {
|
|
@@ -15,16 +16,16 @@ const validateConfig = (props) => {
|
|
|
15
16
|
)
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
const requiredProps =[
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const requiredProps = [
|
|
20
|
+
'apiKey',
|
|
21
|
+
'environment',
|
|
22
|
+
'deliveryToken',
|
|
23
|
+
'homeUrl',
|
|
24
|
+
'awsBase',
|
|
25
|
+
'clientId'
|
|
25
26
|
]
|
|
26
27
|
|
|
27
|
-
requiredProps.forEach(prop => {
|
|
28
|
+
requiredProps.forEach((prop) => {
|
|
28
29
|
if (!props[prop]) {
|
|
29
30
|
throw new Error(`Missing required property ${prop} in config.`)
|
|
30
31
|
}
|
|
@@ -47,7 +48,7 @@ const csProduct = (props) => {
|
|
|
47
48
|
const VARIANT_RESOURCES = 'variants.resources'
|
|
48
49
|
const PRODUCT_CATEGORY = 'categories'
|
|
49
50
|
const PRODUCT_SUBCATEGORIES = 'categories.subcategories'
|
|
50
|
-
const PRODUCT_BRAND_STYLE = 'features.brand_style'
|
|
51
|
+
const PRODUCT_BRAND_STYLE = 'features.brand_style'
|
|
51
52
|
const DEFAULT_LOCALE = 'en'
|
|
52
53
|
const PRODUCT_TYPE = 'product'
|
|
53
54
|
const INCLUDE_FALLBACK = '&include_fallback=true'
|
|
@@ -64,11 +65,17 @@ const csProduct = (props) => {
|
|
|
64
65
|
const bundleRequiredIncludes = `&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_FAQS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${KEY_INGREDIENTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_HIGHLIGHTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_RESOURCES}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANT_KEY_INGREDIENTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANT_HIGHLIGHTS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANT_FAQS}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${VARIANT_RESOURCES}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_CATEGORY}&include[]=${PRODUCT_BUNDLE}.${REQUIRED}${PRODUCT_SUBCATEGORIES}`
|
|
65
66
|
const bundlOptionalIncludes = `&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_FAQS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${KEY_INGREDIENTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_HIGHLIGHTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_RESOURCES}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANT_KEY_INGREDIENTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANT_HIGHLIGHTS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANT_FAQS}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${VARIANT_RESOURCES}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_CATEGORY}&include[]=${PRODUCT_BUNDLE}.${OPTIONAL}${PRODUCT_SUBCATEGORIES}`
|
|
66
67
|
const kit = `&include[]=${PRODUCT_SKU_KIT}.${VARIANTS}&include[]=${PRODUCT_SKU_KIT}.${VARIANTS}.${VARIANT}`
|
|
67
|
-
|
|
68
68
|
|
|
69
69
|
validateConfig(props)
|
|
70
|
-
const {
|
|
71
|
-
|
|
70
|
+
const {
|
|
71
|
+
apiKey,
|
|
72
|
+
environment,
|
|
73
|
+
deliveryToken,
|
|
74
|
+
homeUrl,
|
|
75
|
+
awsBase,
|
|
76
|
+
clientId
|
|
77
|
+
} = props
|
|
78
|
+
const axios = deliveryAxios({ apiKey, deliveryToken })
|
|
72
79
|
|
|
73
80
|
const asObject = () => {
|
|
74
81
|
return props
|
|
@@ -91,7 +98,13 @@ const csProduct = (props) => {
|
|
|
91
98
|
let status = {}
|
|
92
99
|
let marketData = {}
|
|
93
100
|
if (validSkus?.length > 0) {
|
|
94
|
-
status = await getProductStatus(
|
|
101
|
+
status = await getProductStatus(
|
|
102
|
+
validSkus,
|
|
103
|
+
locale,
|
|
104
|
+
homeUrl,
|
|
105
|
+
awsBase,
|
|
106
|
+
clientId
|
|
107
|
+
)
|
|
95
108
|
const localeSplit = locale.split('_')
|
|
96
109
|
let market =
|
|
97
110
|
localeSplit?.length > 1 ? localeSplit[1].toUpperCase() : 'XX'
|
|
@@ -153,7 +166,9 @@ const csProduct = (props) => {
|
|
|
153
166
|
result[type] = strings
|
|
154
167
|
return result
|
|
155
168
|
}, {})
|
|
156
|
-
translation.subscriptions = helpers.mapSubscriptions(
|
|
169
|
+
translation.subscriptions = helpers.mapSubscriptions(
|
|
170
|
+
translation?.subscriptions
|
|
171
|
+
)
|
|
157
172
|
}
|
|
158
173
|
}
|
|
159
174
|
}
|
|
@@ -173,13 +188,15 @@ const csProduct = (props) => {
|
|
|
173
188
|
const formattedBundle = transformBundle(bundle, homeUrl)
|
|
174
189
|
|
|
175
190
|
formattedBundle.requiredProducts = formattedBundle?.requiredProducts?.map(
|
|
176
|
-
({product, quantity}) => {
|
|
191
|
+
({ product, quantity }) => {
|
|
177
192
|
if (product) {
|
|
178
193
|
if (noFormat) {
|
|
179
|
-
return {product
|
|
194
|
+
return { product: product, quantity }
|
|
180
195
|
}
|
|
181
|
-
const [formattedProduct] = formatProductWithSchema([
|
|
182
|
-
|
|
196
|
+
const [formattedProduct] = formatProductWithSchema([
|
|
197
|
+
product
|
|
198
|
+
])
|
|
199
|
+
return { product: formattedProduct, quantity }
|
|
183
200
|
} else {
|
|
184
201
|
return {}
|
|
185
202
|
}
|
|
@@ -187,13 +204,15 @@ const csProduct = (props) => {
|
|
|
187
204
|
)
|
|
188
205
|
|
|
189
206
|
formattedBundle.optionalProducts = formattedBundle?.optionalProducts?.map(
|
|
190
|
-
({product, quantity}) => {
|
|
207
|
+
({ product, quantity }) => {
|
|
191
208
|
if (product) {
|
|
192
209
|
if (noFormat) {
|
|
193
|
-
return {product
|
|
210
|
+
return { product: product, quantity }
|
|
194
211
|
}
|
|
195
|
-
const [formattedProduct] = formatProductWithSchema([
|
|
196
|
-
|
|
212
|
+
const [formattedProduct] = formatProductWithSchema([
|
|
213
|
+
product
|
|
214
|
+
])
|
|
215
|
+
return { product: formattedProduct, quantity }
|
|
197
216
|
} else {
|
|
198
217
|
return {}
|
|
199
218
|
}
|
|
@@ -252,39 +271,55 @@ const csProduct = (props) => {
|
|
|
252
271
|
for (let p = 0; p < products.length; p++) {
|
|
253
272
|
let noFormat = false
|
|
254
273
|
if (products[p]?.sku_kit?.length > 0) {
|
|
255
|
-
products[p].type =
|
|
256
|
-
products[p].product_bundle = await convertKitToRequiredProducts(
|
|
274
|
+
products[p].type = 'kit'
|
|
275
|
+
products[p].product_bundle = await convertKitToRequiredProducts(
|
|
276
|
+
products[p].sku_kit,
|
|
277
|
+
locale
|
|
278
|
+
)
|
|
257
279
|
noFormat = true
|
|
258
|
-
}
|
|
280
|
+
}
|
|
259
281
|
if (products[p]?.product_bundle?.length > 0) {
|
|
260
|
-
for (
|
|
282
|
+
for (
|
|
283
|
+
let b = 0;
|
|
284
|
+
b < products[p]?.product_bundle?.length || 0;
|
|
285
|
+
b++
|
|
286
|
+
) {
|
|
261
287
|
for (
|
|
262
288
|
let i = 0;
|
|
263
|
-
i <
|
|
289
|
+
i <
|
|
290
|
+
(products[p].product_bundle[b].required_products || [])
|
|
291
|
+
.length;
|
|
264
292
|
i++
|
|
265
293
|
) {
|
|
266
294
|
await removeInvalidVariants(
|
|
267
|
-
products[p].product_bundle[b].required_products[i]
|
|
295
|
+
products[p].product_bundle[b].required_products[i]
|
|
296
|
+
.product,
|
|
268
297
|
locale,
|
|
269
298
|
translations
|
|
270
299
|
)
|
|
271
300
|
}
|
|
272
301
|
for (
|
|
273
302
|
let i = 0;
|
|
274
|
-
i <
|
|
303
|
+
i <
|
|
304
|
+
(products[p].product_bundle[b].optional_products || [])
|
|
305
|
+
.length;
|
|
275
306
|
i++
|
|
276
307
|
) {
|
|
277
308
|
await removeInvalidVariants(
|
|
278
|
-
products[p].product_bundle[b].optional_products[i]
|
|
309
|
+
products[p].product_bundle[b].optional_products[i]
|
|
310
|
+
.product,
|
|
279
311
|
locale,
|
|
280
312
|
translations
|
|
281
313
|
)
|
|
282
314
|
}
|
|
283
315
|
}
|
|
284
|
-
if(products[p].product_bundle?.length > 0){
|
|
285
|
-
products[p].bundle = formatKitWithSchema(
|
|
286
|
-
|
|
287
|
-
|
|
316
|
+
if (products[p].product_bundle?.length > 0) {
|
|
317
|
+
products[p].bundle = formatKitWithSchema(
|
|
318
|
+
products[p].product_bundle,
|
|
319
|
+
noFormat
|
|
320
|
+
)
|
|
321
|
+
products[p].variants = []
|
|
322
|
+
products[p].type = products[p].type || 'bundle'
|
|
288
323
|
products[p].bundle[0].type = products[p].type
|
|
289
324
|
delete products[p].product_bundle
|
|
290
325
|
}
|
|
@@ -329,10 +364,8 @@ const csProduct = (props) => {
|
|
|
329
364
|
try {
|
|
330
365
|
const res = await axios(url)
|
|
331
366
|
|
|
332
|
-
if (onlyEntries)
|
|
333
|
-
|
|
334
|
-
else
|
|
335
|
-
return res?.data?.entries ? res.data : res;
|
|
367
|
+
if (onlyEntries) return res?.data?.entries ? res.data.entries : res
|
|
368
|
+
else return res?.data?.entries ? res.data : res
|
|
336
369
|
} catch (error) {
|
|
337
370
|
return error
|
|
338
371
|
}
|
|
@@ -347,7 +380,7 @@ const csProduct = (props) => {
|
|
|
347
380
|
const bundles = await getBundles(id, locale)
|
|
348
381
|
return bundles && bundles[0] ? bundles[0] : null
|
|
349
382
|
}
|
|
350
|
-
|
|
383
|
+
|
|
351
384
|
const getBundles = async (ids, locale) => {
|
|
352
385
|
if (!Array.isArray(ids)) {
|
|
353
386
|
ids = [ids]
|
|
@@ -435,7 +468,7 @@ const csProduct = (props) => {
|
|
|
435
468
|
const translations = await getEntriesByQuery({
|
|
436
469
|
contentType: 'strings_product_detail_page',
|
|
437
470
|
locale,
|
|
438
|
-
includes: ['common_strings'
|
|
471
|
+
includes: ['common_strings']
|
|
439
472
|
})
|
|
440
473
|
await parseSharedStrings(translations)
|
|
441
474
|
return translations
|
|
@@ -448,6 +481,31 @@ const csProduct = (props) => {
|
|
|
448
481
|
)
|
|
449
482
|
return formattedTranslations
|
|
450
483
|
}
|
|
484
|
+
const getTranslationsForCategoryPage = async (
|
|
485
|
+
locale,
|
|
486
|
+
contentType,
|
|
487
|
+
includes = []
|
|
488
|
+
) => {
|
|
489
|
+
const translations = await getEntriesByQuery({
|
|
490
|
+
contentType,
|
|
491
|
+
locale,
|
|
492
|
+
includes
|
|
493
|
+
})
|
|
494
|
+
await parseSharedStrings(translations)
|
|
495
|
+
return translations
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const getCategoryPageTranslations = async (locale) => {
|
|
499
|
+
const translations = await getTranslationsForCategoryPage(
|
|
500
|
+
locale,
|
|
501
|
+
'strings_category_page',
|
|
502
|
+
['common_strings']
|
|
503
|
+
)
|
|
504
|
+
const formattedTranslations = translations.map((translate) =>
|
|
505
|
+
formatCategoryTranslations(translate)
|
|
506
|
+
)
|
|
507
|
+
return formattedTranslations
|
|
508
|
+
}
|
|
451
509
|
|
|
452
510
|
const publishedProducts = async ({ locale, skip = 0, limit = 50 } = {}) => {
|
|
453
511
|
let products = await getEntriesByQuery({
|
|
@@ -481,7 +539,8 @@ const csProduct = (props) => {
|
|
|
481
539
|
formatTranslations,
|
|
482
540
|
getProductTranslations,
|
|
483
541
|
getBundle,
|
|
484
|
-
getBundles
|
|
542
|
+
getBundles,
|
|
543
|
+
getCategoryPageTranslations
|
|
485
544
|
}
|
|
486
545
|
}
|
|
487
546
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const formatCategoryTranslations = (parent) => ({
|
|
2
|
+
sortBy: parent?.common_strings?.category_page?.sort_by,
|
|
3
|
+
sortByPriceLowToHigh:
|
|
4
|
+
parent?.common_strings?.category_page?.sortbypricelowtohigh,
|
|
5
|
+
sortByPriceHightToLow:
|
|
6
|
+
parent?.common_strings?.category_page?.sortbypricehightolow,
|
|
7
|
+
showMore: parent?.common_strings?.category_page?.show_more,
|
|
8
|
+
products: parent?.common_strings?.category_page?.products,
|
|
9
|
+
sortbyatoz: parent?.common_strings?.category_page?.sortbyatoz,
|
|
10
|
+
sortbyztoa: parent?.common_strings?.category_page?.sortbyztoa,
|
|
11
|
+
sortbyfeatured: parent?.common_strings?.category_page?.sortbyfeatured
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
formatCategoryTranslations
|
|
16
|
+
}
|
package/src/formatKit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { isNullOrEmpty } = require('@nuskin/ns-common-lib')
|
|
1
|
+
const { isNullOrEmpty } = require('@nuskin/ns-common-lib')
|
|
2
2
|
const moment = require('moment')
|
|
3
3
|
|
|
4
4
|
const parseStatus = (variant) => {
|
|
@@ -6,30 +6,53 @@ const parseStatus = (variant) => {
|
|
|
6
6
|
|
|
7
7
|
if (variant?.type !== 'bundle' && variant?.type !== 'kit') {
|
|
8
8
|
return {
|
|
9
|
-
status: variant?.status?.status,
|
|
10
|
-
isBackordered: variant?.status?.isBackordered,
|
|
9
|
+
status: variant?.status?.status,
|
|
10
|
+
isBackordered: variant?.status?.isBackordered,
|
|
11
11
|
backorderedAvailableDate: variant?.status?.backorderedAvailableDate
|
|
12
12
|
}
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
|
|
15
15
|
let isBackordered = false
|
|
16
16
|
let backorderedAvailableDate = null
|
|
17
17
|
if (variant?.type === 'kit') {
|
|
18
18
|
try {
|
|
19
|
-
|
|
19
|
+
/* eslint-disable no-unsafe-optional-chaining */
|
|
20
|
+
const latestBODate = Math.max(
|
|
21
|
+
...variant?.requiredProducts?.flatMap((a) =>
|
|
22
|
+
a?.product?.variants?.map(
|
|
23
|
+
(s) =>
|
|
24
|
+
Number(
|
|
25
|
+
new Date(s?.status?.backorderedAvailableDate)
|
|
26
|
+
) || 0
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
)
|
|
20
30
|
if (latestBODate) {
|
|
21
31
|
isBackordered = true
|
|
22
|
-
backorderedAvailableDate = moment(
|
|
32
|
+
backorderedAvailableDate = moment(
|
|
33
|
+
new Date(latestBODate)
|
|
34
|
+
).format(dateFormat)
|
|
23
35
|
}
|
|
24
36
|
} catch {
|
|
25
37
|
backorderedAvailableDate = null
|
|
26
38
|
}
|
|
27
39
|
} else if (variant?.type === 'bundle') {
|
|
28
40
|
try {
|
|
29
|
-
const latestBODate = Math.max(
|
|
41
|
+
const latestBODate = Math.max(
|
|
42
|
+
...variant?.requiredProducts?.flatMap(
|
|
43
|
+
(a) =>
|
|
44
|
+
Number(
|
|
45
|
+
new Date(
|
|
46
|
+
a?.product?.variants[0]?.status?.backorderedAvailableDate
|
|
47
|
+
)
|
|
48
|
+
) || 0
|
|
49
|
+
)
|
|
50
|
+
)
|
|
30
51
|
if (latestBODate) {
|
|
31
52
|
isBackordered = true
|
|
32
|
-
backorderedAvailableDate = moment(
|
|
53
|
+
backorderedAvailableDate = moment(
|
|
54
|
+
new Date(latestBODate)
|
|
55
|
+
).format(dateFormat)
|
|
33
56
|
}
|
|
34
57
|
} catch {
|
|
35
58
|
backorderedAvailableDate = null
|
|
@@ -37,29 +60,31 @@ const parseStatus = (variant) => {
|
|
|
37
60
|
}
|
|
38
61
|
return {
|
|
39
62
|
// changed
|
|
40
|
-
status: variant?.status?.status,
|
|
41
|
-
isBackordered: isBackordered,
|
|
63
|
+
status: variant?.status?.status,
|
|
64
|
+
isBackordered: isBackordered,
|
|
42
65
|
backorderedAvailableDate: backorderedAvailableDate
|
|
43
66
|
}
|
|
44
|
-
}
|
|
67
|
+
}
|
|
45
68
|
|
|
46
69
|
const parsePrice = (product = []) => {
|
|
47
|
-
const requiredProducts = !isNullOrEmpty(product)
|
|
70
|
+
const requiredProducts = !isNullOrEmpty(product)
|
|
71
|
+
? product?.map((p) => p?.requiredProducts).flat()
|
|
72
|
+
: []
|
|
48
73
|
|
|
49
|
-
const variants = requiredProducts?.map(p => {
|
|
74
|
+
const variants = requiredProducts?.map((p) => {
|
|
50
75
|
const [firstVariant] = p?.product?.variants || []
|
|
51
|
-
return {...firstVariant, quantity: p?.quantity}
|
|
76
|
+
return { ...firstVariant, quantity: p?.quantity }
|
|
52
77
|
})
|
|
53
78
|
|
|
54
|
-
const defaultValues =
|
|
55
|
-
price
|
|
79
|
+
const defaultValues = {
|
|
80
|
+
price: {
|
|
56
81
|
retail: 0,
|
|
57
|
-
retailSubscription
|
|
58
|
-
wholesale
|
|
59
|
-
wholesaleSubscription
|
|
82
|
+
retailSubscription: 0,
|
|
83
|
+
wholesale: 0,
|
|
84
|
+
wholesaleSubscription: 0
|
|
60
85
|
},
|
|
61
|
-
points
|
|
62
|
-
subscription
|
|
86
|
+
points: {
|
|
87
|
+
subscription: {
|
|
63
88
|
cv: 0,
|
|
64
89
|
pv: 0,
|
|
65
90
|
sb: 0
|
|
@@ -72,35 +97,72 @@ const parsePrice = (product = []) => {
|
|
|
72
97
|
}
|
|
73
98
|
}
|
|
74
99
|
|
|
75
|
-
// sum of price and points from 1st variant of product bundle
|
|
100
|
+
// sum of price and points from 1st variant of product bundle
|
|
76
101
|
const sumOfPriceAndPoints = variants?.reduce((acc, curr) => {
|
|
77
102
|
const price = {}
|
|
78
103
|
const points = {
|
|
79
|
-
subscription
|
|
80
|
-
wholesale
|
|
104
|
+
subscription: {},
|
|
105
|
+
wholesale: {}
|
|
81
106
|
}
|
|
82
107
|
|
|
83
|
-
price.retail =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
price.
|
|
108
|
+
price.retail =
|
|
109
|
+
Number(acc?.price?.retail || 0) +
|
|
110
|
+
Number((curr?.price?.retail || 0) * (curr?.quantity || 1))
|
|
111
|
+
price.retailSubscription =
|
|
112
|
+
Number(acc?.price?.retailSubscription || 0) +
|
|
113
|
+
Number(
|
|
114
|
+
(curr?.price?.retailSubscription || 0) * (curr?.quantity || 1)
|
|
115
|
+
)
|
|
116
|
+
price.wholesale =
|
|
117
|
+
Number(acc?.price?.wholesale || 0) +
|
|
118
|
+
Number((curr?.price?.wholesale || 0) * (curr?.quantity || 1))
|
|
119
|
+
price.wholesaleSubscription =
|
|
120
|
+
Number(acc?.price?.wholesaleSubscription || 0) +
|
|
121
|
+
Number(
|
|
122
|
+
(curr?.price?.wholesaleSubscription || 0) *
|
|
123
|
+
(curr?.quantity || 1)
|
|
124
|
+
)
|
|
87
125
|
price.currencyCode = curr?.price?.currencyCode
|
|
88
126
|
|
|
89
|
-
points.subscription.cv =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
points.
|
|
127
|
+
points.subscription.cv =
|
|
128
|
+
Number(acc?.points?.subscription?.cv || 0) +
|
|
129
|
+
Number(
|
|
130
|
+
(curr?.points?.subscription?.cv || 0) * (curr?.quantity || 1)
|
|
131
|
+
)
|
|
132
|
+
points.subscription.pv =
|
|
133
|
+
Number(acc?.points?.subscription?.pv || 0) +
|
|
134
|
+
Number(
|
|
135
|
+
(curr?.points?.subscription?.pv || 0) * (curr?.quantity || 1)
|
|
136
|
+
)
|
|
137
|
+
points.subscription.sb =
|
|
138
|
+
Number(acc?.points?.subscription?.sb || 0) +
|
|
139
|
+
Number(
|
|
140
|
+
(curr?.points?.subscription?.sb || 0) * (curr?.quantity || 1)
|
|
141
|
+
)
|
|
142
|
+
points.wholesale.cv =
|
|
143
|
+
Number(acc?.points?.wholesale?.cv || 0) +
|
|
144
|
+
Number((curr?.points?.wholesale?.cv || 0) * (curr?.quantity || 1))
|
|
145
|
+
points.wholesale.pv =
|
|
146
|
+
Number(acc?.points?.wholesale?.pv || 0) +
|
|
147
|
+
Number((curr?.points?.wholesale?.pv || 0) * (curr?.quantity || 1))
|
|
148
|
+
points.wholesale.sb =
|
|
149
|
+
Number(acc?.points?.wholesale?.sb || 0) +
|
|
150
|
+
Number((curr?.points?.wholesale?.sb || 0) * (curr?.quantity || 1))
|
|
95
151
|
|
|
96
|
-
return { price, points}
|
|
152
|
+
return { price, points }
|
|
97
153
|
}, defaultValues)
|
|
98
154
|
return sumOfPriceAndPoints
|
|
99
155
|
}
|
|
100
156
|
|
|
101
157
|
const parseKitAvailableQuantity = (kit) => {
|
|
102
158
|
try {
|
|
103
|
-
return
|
|
159
|
+
return (
|
|
160
|
+
Math.min(
|
|
161
|
+
...kit.flatMap((a) =>
|
|
162
|
+
a?.sku?.map((s) => s?.inventoryProperties?.atpQty)
|
|
163
|
+
)
|
|
164
|
+
) || 0
|
|
165
|
+
)
|
|
104
166
|
} catch {
|
|
105
167
|
return 0
|
|
106
168
|
}
|
|
@@ -108,11 +170,13 @@ const parseKitAvailableQuantity = (kit) => {
|
|
|
108
170
|
|
|
109
171
|
const parseBundleAvailableQuantity = (product) => {
|
|
110
172
|
try {
|
|
111
|
-
const {requiredProducts = []} = !isNullOrEmpty(product) ? product : {}
|
|
112
|
-
const quantities = requiredProducts?.map(p=>
|
|
173
|
+
const { requiredProducts = [] } = !isNullOrEmpty(product) ? product : {}
|
|
174
|
+
const quantities = requiredProducts?.map((p) =>
|
|
175
|
+
p?.product?.variants?.map((a) => a?.availableQuantity)
|
|
176
|
+
)
|
|
113
177
|
return Math.min(...quantities) || 0
|
|
114
178
|
} catch {
|
|
115
|
-
console.log(
|
|
179
|
+
console.log('some error in availableQuantity')
|
|
116
180
|
return 0
|
|
117
181
|
}
|
|
118
182
|
}
|
|
@@ -137,10 +201,10 @@ const parseKit = (product, market) => {
|
|
|
137
201
|
kits.points = priceData?.points
|
|
138
202
|
kits.price = priceData?.price
|
|
139
203
|
kits.purchaseTypes = {
|
|
140
|
-
buyOnce: kits?.availableChannels?.includes('web'),
|
|
204
|
+
buyOnce: kits?.availableChannels?.includes('web'),
|
|
141
205
|
subscription: kits?.availableChannels?.includes('subscription')
|
|
142
206
|
}
|
|
143
|
-
kits.retailDiscount= properties?.retailDiscount
|
|
207
|
+
kits.retailDiscount = properties?.retailDiscount
|
|
144
208
|
kits.wholesaleDiscount = properties?.wholesaleDiscount
|
|
145
209
|
kits.pvDiscount = properties?.pvDiscount
|
|
146
210
|
kits.cvDiscount = properties?.cvDiscount
|
|
@@ -149,7 +213,8 @@ const parseKit = (product, market) => {
|
|
|
149
213
|
kits.scanQualifiedCount = properties?.scanQualifiedCount
|
|
150
214
|
// newVariant.slug = undefined
|
|
151
215
|
kits.status = parseStatus(properties)
|
|
152
|
-
if ((kits?.status || {})?.status === 'active')
|
|
216
|
+
if ((kits?.status || {})?.status === 'active')
|
|
217
|
+
kits.status.status = 'sellable'
|
|
153
218
|
const kitProducts = []
|
|
154
219
|
if (properties?.type === 'kit' && product?.kit) {
|
|
155
220
|
kits.type = 'kit'
|
|
@@ -157,23 +222,38 @@ const parseKit = (product, market) => {
|
|
|
157
222
|
for (const kit of product?.kit || []) {
|
|
158
223
|
const kitProduct = formatKit(kit, market)
|
|
159
224
|
kitProduct.id = kit?.identifier
|
|
160
|
-
kitProducts.push({
|
|
225
|
+
kitProducts.push({
|
|
226
|
+
product: kitProduct,
|
|
227
|
+
quantity: (kit?.properties || {})?.quantity || 0,
|
|
228
|
+
isMandatory: true
|
|
229
|
+
})
|
|
161
230
|
}
|
|
162
|
-
} else if (
|
|
231
|
+
} else if (
|
|
232
|
+
properties?.type === 'bundle' ||
|
|
233
|
+
(properties?.type === 'kit' && properties?.requiredProducts)
|
|
234
|
+
) {
|
|
163
235
|
kits.type = properties?.type
|
|
164
236
|
kits.availableQuantity = parseBundleAvailableQuantity(properties)
|
|
165
237
|
for (const kit of properties?.requiredProducts || []) {
|
|
166
238
|
if (kit?.product) {
|
|
167
239
|
const kitProduct = formatKit(kit?.product, market)
|
|
168
240
|
kitProduct.id = kit?.product?.id
|
|
169
|
-
kitProducts?.push({
|
|
241
|
+
kitProducts?.push({
|
|
242
|
+
product: kitProduct,
|
|
243
|
+
quantity: kit?.quantity || 0,
|
|
244
|
+
isMandatory: true
|
|
245
|
+
})
|
|
170
246
|
}
|
|
171
247
|
}
|
|
172
248
|
for (const kit of properties?.optionalProducts || []) {
|
|
173
249
|
if (kit?.product) {
|
|
174
250
|
const kitProduct = formatKit(kit?.product, market)
|
|
175
251
|
kitProduct.id = kit?.product?.id
|
|
176
|
-
kitProducts?.push({
|
|
252
|
+
kitProducts?.push({
|
|
253
|
+
product: kitProduct,
|
|
254
|
+
quantity: kit?.quantity || 0,
|
|
255
|
+
isMandatory: false
|
|
256
|
+
})
|
|
177
257
|
}
|
|
178
258
|
}
|
|
179
259
|
}
|
|
@@ -182,23 +262,20 @@ const parseKit = (product, market) => {
|
|
|
182
262
|
}
|
|
183
263
|
|
|
184
264
|
const formatKit = (product, market) => {
|
|
185
|
-
|
|
186
265
|
if (!product) {
|
|
187
266
|
return {}
|
|
188
267
|
}
|
|
189
268
|
|
|
190
269
|
let kit = null
|
|
191
|
-
if(['kit', 'bundle'].includes(product?.type)) {
|
|
270
|
+
if (['kit', 'bundle'].includes(product?.type)) {
|
|
192
271
|
kit = parseKit(product?.bundle, market)
|
|
193
272
|
}
|
|
194
273
|
return {
|
|
195
274
|
...product,
|
|
196
|
-
bundle: kit
|
|
197
|
-
|
|
275
|
+
bundle: kit
|
|
198
276
|
}
|
|
199
277
|
}
|
|
200
278
|
|
|
201
|
-
|
|
202
279
|
module.exports = {
|
|
203
280
|
formatKit,
|
|
204
281
|
parseKit,
|
|
@@ -207,4 +284,3 @@ module.exports = {
|
|
|
207
284
|
parsePrice,
|
|
208
285
|
parseStatus
|
|
209
286
|
}
|
|
210
|
-
|
package/src/formatProduct.js
CHANGED
|
@@ -11,8 +11,7 @@ const formatProduct = (parent, homeUrl) => {
|
|
|
11
11
|
slug: parent?.seo_information?.slug,
|
|
12
12
|
variantSelectLabel: parent?.variant_select_label,
|
|
13
13
|
secondaryTitle: parent?.secondary_title,
|
|
14
|
-
title: parent?.
|
|
15
|
-
name: parent?.name || parent?.defaults?.name,
|
|
14
|
+
title: parent?.name,
|
|
16
15
|
productImages: helpers?.getProductImages(parent),
|
|
17
16
|
salesLabel: parent?.sales_label,
|
|
18
17
|
salesText: parent?.sales_text,
|
|
@@ -100,7 +100,8 @@ const formatTranslations = (parent) => ({
|
|
|
100
100
|
provenResults: parent?.proven_results,
|
|
101
101
|
socialImpactAndSustainability: parent?.social_impact_and_sustainability,
|
|
102
102
|
recommendations: parent?.recommendations,
|
|
103
|
-
recommendedProductsSectionHeading:
|
|
103
|
+
recommendedProductsSectionHeading:
|
|
104
|
+
parent?.recommended_products_section_heading,
|
|
104
105
|
resources: parent?.resources,
|
|
105
106
|
resourcesSubtitle: parent?.resources_subtitle,
|
|
106
107
|
selectPurchaseType: parent?.select_purchase_type,
|
|
@@ -163,8 +164,10 @@ const formatTranslations = (parent) => ({
|
|
|
163
164
|
signIn: parent?.common_strings?.accounts?.sign_in
|
|
164
165
|
},
|
|
165
166
|
kitAndOrBundle: {
|
|
166
|
-
thisKitContainsAmountItems:
|
|
167
|
-
|
|
167
|
+
thisKitContainsAmountItems:
|
|
168
|
+
parent?.kit_and_or_bundle?.this_kit_contains_amount_items,
|
|
169
|
+
moreDetailsOnTheProductPageHere:
|
|
170
|
+
parent?.kit_and_or_bundle?.more_details_on_the_product_page_here,
|
|
168
171
|
addMoreToYourBundle: parent?.kit_and_or_bundle?.add_more_to_your_bundle
|
|
169
172
|
},
|
|
170
173
|
promoteApps: {
|
|
@@ -175,8 +178,10 @@ const formatTranslations = (parent) => ({
|
|
|
175
178
|
buttonText: parent?.promote_apps?.vera?.button_text,
|
|
176
179
|
buttonUrl: parent?.promote_apps?.vera?.button_url,
|
|
177
180
|
delay: parent?.promote_apps?.vera?.delay,
|
|
178
|
-
promoteVeraIsActive:
|
|
179
|
-
|
|
181
|
+
promoteVeraIsActive:
|
|
182
|
+
parent?.promote_apps?.vera?.promote_vera_is_active,
|
|
183
|
+
hidePromoteVeraStorageItem:
|
|
184
|
+
parent?.promote_apps?.vera?.hide_promote_vera_storage_item
|
|
180
185
|
}
|
|
181
186
|
}
|
|
182
187
|
})
|
package/src/formatVariant.js
CHANGED
|
@@ -9,11 +9,10 @@ const formatVariant = (parent) => ({
|
|
|
9
9
|
globalId: parent?.sap_data?.global_id,
|
|
10
10
|
sku: helpers?.getBestSkuData(parent)?.sku,
|
|
11
11
|
slug: parent?.slug,
|
|
12
|
-
name: parent?.name || parent?.defaults?.name,
|
|
13
12
|
size: parent?.size,
|
|
14
13
|
variantLabel: parent?.select_label,
|
|
15
14
|
variantColor: parent?.select_color,
|
|
16
|
-
title: parent?.
|
|
15
|
+
title: parent?.name || parent?.defaults?.name,
|
|
17
16
|
salesLabel: parent?.sales_label,
|
|
18
17
|
salesText: parent?.sales_text,
|
|
19
18
|
description: entities?.decodeHTML(
|
package/src/transformBundle.js
CHANGED
|
@@ -4,8 +4,7 @@ const helpers = require('./helpers')
|
|
|
4
4
|
const transformBundle = (parent, homeUrl) => ({
|
|
5
5
|
id: parent?.bundle_id || parent?.kit_id,
|
|
6
6
|
uid: parent?.uid,
|
|
7
|
-
title: parent?.
|
|
8
|
-
name: parent?.name || parent?.defaults?.name,
|
|
7
|
+
title: parent?.name,
|
|
9
8
|
type: parent?.type,
|
|
10
9
|
requiredProducts: parent?.required_products?.map((r) => ({
|
|
11
10
|
product: r?.product?.[0],
|