@nuskin/cs-product-lib 1.1.3-cx12-8656.2 → 1.1.3
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 +69 -27
- package/src/formatKit.js +125 -68
- package/src/formatVariant.js +101 -112
- package/src/productStatus.js +0 -1
package/package.json
CHANGED
package/src/csProduct.js
CHANGED
|
@@ -83,6 +83,21 @@ const csProduct = (props) => {
|
|
|
83
83
|
return props
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
const badLocaleMap = (locale) => {
|
|
87
|
+
if (typeof locale !== 'string') {
|
|
88
|
+
return locale
|
|
89
|
+
}
|
|
90
|
+
// Change known changed locales to their new locale
|
|
91
|
+
switch (locale.toLowerCase()) {
|
|
92
|
+
case 'id-in' :
|
|
93
|
+
return 'ID-id'
|
|
94
|
+
case 'hu-hu':
|
|
95
|
+
return 'HU-hu'
|
|
96
|
+
default:
|
|
97
|
+
return locale
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
86
101
|
const removeInvalidVariants = async (products = [], locale, translations) => {
|
|
87
102
|
const validSkus = []
|
|
88
103
|
for (const product of products) {
|
|
@@ -134,9 +149,6 @@ const csProduct = (props) => {
|
|
|
134
149
|
validVariants.push({
|
|
135
150
|
...variant,
|
|
136
151
|
status: varStatus,
|
|
137
|
-
backorderQuantity: varStatus?.backordered ? varStatus?.availableQuantity : 0,
|
|
138
|
-
availableQuantity: varStatus?.backordered ? 0 : varStatus?.availableQuantity,
|
|
139
|
-
backorderedAvailableDate: varStatus?.backorderedAvailableDate || null,
|
|
140
152
|
marketData
|
|
141
153
|
})
|
|
142
154
|
}
|
|
@@ -408,6 +420,7 @@ const csProduct = (props) => {
|
|
|
408
420
|
* @returns
|
|
409
421
|
*/
|
|
410
422
|
const getBundles = async (ids, locale) => {
|
|
423
|
+
locale = badLocaleMap(locale)
|
|
411
424
|
if (!Array.isArray(ids)) {
|
|
412
425
|
ids = [ids]
|
|
413
426
|
}
|
|
@@ -420,17 +433,19 @@ const csProduct = (props) => {
|
|
|
420
433
|
{"sku_kit":{"$in_query":{"uid":{"$in": ${idString}}}}}
|
|
421
434
|
]}`
|
|
422
435
|
const products = await queryProducts(query, locale)
|
|
423
|
-
if (products.length > 0) {
|
|
436
|
+
if (Array.isArray(products) && products.length > 0) {
|
|
424
437
|
const translations = await getTranslations(locale)
|
|
425
438
|
await formatKit(products, locale, translations)
|
|
426
439
|
await removeInvalidVariants(products, locale, translations)
|
|
427
440
|
return formatProductWithSchema(products)
|
|
428
|
-
} else {
|
|
429
|
-
return []
|
|
430
441
|
}
|
|
442
|
+
const errorResponse = products.response || {}
|
|
443
|
+
const responseData = errorResponse.data || {}
|
|
444
|
+
return [{error: {message: products.message, name: products.name, status: errorResponse.status, errors: [`${responseData.error_code}: ${responseData.error_message}`]}}]
|
|
431
445
|
}
|
|
432
446
|
|
|
433
447
|
const getProductsBySku = async (skus, locale) => {
|
|
448
|
+
locale = badLocaleMap(locale)
|
|
434
449
|
if (!Array.isArray(skus)) {
|
|
435
450
|
skus = [skus]
|
|
436
451
|
}
|
|
@@ -439,17 +454,23 @@ const csProduct = (props) => {
|
|
|
439
454
|
)}}}}}`
|
|
440
455
|
|
|
441
456
|
let products = await queryProducts(query, locale)
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
product
|
|
447
|
-
|
|
457
|
+
if (Array.isArray(products)) {
|
|
458
|
+
const translations = await getTranslations(locale)
|
|
459
|
+
await formatKit(products, locale, translations)
|
|
460
|
+
await removeInvalidVariants(products, locale, translations)
|
|
461
|
+
for (const product of products) {
|
|
462
|
+
product.skus = skus
|
|
463
|
+
product.locale = locale
|
|
464
|
+
}
|
|
465
|
+
return formatProductWithSchema(products)
|
|
448
466
|
}
|
|
449
|
-
|
|
467
|
+
const errorResponse = products.response || {}
|
|
468
|
+
const responseData = errorResponse.data || {}
|
|
469
|
+
return [{error: {message: products.message, name: products.name, status: errorResponse.status, errors: [`${responseData.error_code}: ${responseData.error_message}`]}}]
|
|
450
470
|
}
|
|
451
471
|
|
|
452
472
|
const getProductsByGlobalId = async (ids, locale) => {
|
|
473
|
+
locale = badLocaleMap(locale)
|
|
453
474
|
if (!Array.isArray(ids)) {
|
|
454
475
|
ids = [ids]
|
|
455
476
|
}
|
|
@@ -458,13 +479,19 @@ const csProduct = (props) => {
|
|
|
458
479
|
)}}}}}`
|
|
459
480
|
|
|
460
481
|
let products = await queryProducts(query, locale)
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
482
|
+
if (Array.isArray(products)) {
|
|
483
|
+
const translations = await getTranslations(locale)
|
|
484
|
+
await formatKit(products, locale, translations)
|
|
485
|
+
await removeInvalidVariants(products, locale, translations)
|
|
486
|
+
return formatProductWithSchema(products)
|
|
487
|
+
}
|
|
488
|
+
const errorResponse = products.response || {}
|
|
489
|
+
const responseData = errorResponse.data || {}
|
|
490
|
+
return [{error: {message: products.message, name: products.name, status: errorResponse.status, errors: [`${responseData.error_code}: ${responseData.error_message}`]}}]
|
|
465
491
|
}
|
|
466
492
|
|
|
467
493
|
const getProductsBySlug = async (slugs, locale) => {
|
|
494
|
+
locale = badLocaleMap(locale)
|
|
468
495
|
if (!Array.isArray(slugs)) {
|
|
469
496
|
slugs = [slugs]
|
|
470
497
|
}
|
|
@@ -473,25 +500,37 @@ const csProduct = (props) => {
|
|
|
473
500
|
)}}}`
|
|
474
501
|
|
|
475
502
|
const products = await queryProducts(query, locale)
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
503
|
+
if (Array.isArray(products)) {
|
|
504
|
+
const translations = await getTranslations(locale)
|
|
505
|
+
await formatKit(products, locale, translations)
|
|
506
|
+
await removeInvalidVariants(products, locale, translations)
|
|
507
|
+
return formatProductWithSchema(products)
|
|
508
|
+
}
|
|
509
|
+
const errorResponse = products.response || {}
|
|
510
|
+
const responseData = errorResponse.data || {}
|
|
511
|
+
return [{error: {message: products.message, name: products.name, status: errorResponse.status, errors: [`${responseData.error_code}: ${responseData.error_message}`]}}]
|
|
480
512
|
}
|
|
481
513
|
|
|
482
514
|
const getProductsByUID = async (ids, locale) => {
|
|
515
|
+
locale = badLocaleMap(locale)
|
|
483
516
|
if (!Array.isArray(ids)) {
|
|
484
517
|
ids = [ids]
|
|
485
518
|
}
|
|
486
519
|
const query = `{"uid": {"$in": ${helpers?.arrayString(ids)}}}`
|
|
487
520
|
let products = await queryProducts(query, locale)
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
521
|
+
if (Array.isArray(products)) {
|
|
522
|
+
const translations = await getTranslations(locale)
|
|
523
|
+
await formatKit(products, locale, translations)
|
|
524
|
+
await removeInvalidVariants(products, locale, translations)
|
|
525
|
+
return formatProductWithSchema(products)
|
|
526
|
+
}
|
|
527
|
+
const errorResponse = products.response || {}
|
|
528
|
+
const responseData = errorResponse.data || {}
|
|
529
|
+
return [{error: {message: products.message, name: products.name, status: errorResponse.status, errors: [`${responseData.error_code}: ${responseData.error_message}`]}}]
|
|
492
530
|
}
|
|
493
531
|
|
|
494
532
|
const getTranslations = async (locale) => {
|
|
533
|
+
locale = badLocaleMap(locale)
|
|
495
534
|
const translations = await getEntriesByQuery({
|
|
496
535
|
contentType: 'strings_product_detail_page',
|
|
497
536
|
locale,
|
|
@@ -502,6 +541,7 @@ const csProduct = (props) => {
|
|
|
502
541
|
}
|
|
503
542
|
|
|
504
543
|
const getProductTranslations = async (locale) => {
|
|
544
|
+
locale = badLocaleMap(locale)
|
|
505
545
|
const translations = await getTranslations(locale)
|
|
506
546
|
const formattedTranslations = translations.map((translate) =>
|
|
507
547
|
formatTranslations(translate)
|
|
@@ -513,6 +553,7 @@ const csProduct = (props) => {
|
|
|
513
553
|
contentType,
|
|
514
554
|
includes = []
|
|
515
555
|
) => {
|
|
556
|
+
locale = badLocaleMap(locale)
|
|
516
557
|
const translations = await getEntriesByQuery({
|
|
517
558
|
contentType,
|
|
518
559
|
locale,
|
|
@@ -523,6 +564,7 @@ const csProduct = (props) => {
|
|
|
523
564
|
}
|
|
524
565
|
|
|
525
566
|
const getCategoryPageTranslations = async (locale) => {
|
|
567
|
+
locale = badLocaleMap(locale)
|
|
526
568
|
const translations = await getTranslationsForCategoryPage(
|
|
527
569
|
locale,
|
|
528
570
|
'strings_category_page',
|
|
@@ -535,6 +577,7 @@ const csProduct = (props) => {
|
|
|
535
577
|
}
|
|
536
578
|
|
|
537
579
|
const publishedProducts = async ({ locale, skip = 0, limit = 50 } = {}) => {
|
|
580
|
+
locale = badLocaleMap(locale)
|
|
538
581
|
let products = await getEntriesByQuery({
|
|
539
582
|
locale,
|
|
540
583
|
start: skip,
|
|
@@ -567,8 +610,7 @@ const csProduct = (props) => {
|
|
|
567
610
|
getProductTranslations,
|
|
568
611
|
getBundle,
|
|
569
612
|
getBundles,
|
|
570
|
-
getCategoryPageTranslations
|
|
571
|
-
formatProductWithSchema
|
|
613
|
+
getCategoryPageTranslations
|
|
572
614
|
}
|
|
573
615
|
}
|
|
574
616
|
|
package/src/formatKit.js
CHANGED
|
@@ -2,6 +2,71 @@ const { isNullOrEmpty, isTrue } = require('@nuskin/ns-common-lib');
|
|
|
2
2
|
const { formatDiscounts } = require('./helpers/formatDiscounts');
|
|
3
3
|
const moment = require('moment')
|
|
4
4
|
|
|
5
|
+
const parseStatus = (variant) => {
|
|
6
|
+
const dateFormat = 'YYYY-MM-DD'
|
|
7
|
+
|
|
8
|
+
if (variant?.type !== 'bundle' && variant?.type !== 'kit') {
|
|
9
|
+
return {
|
|
10
|
+
status: variant?.status?.status,
|
|
11
|
+
isBackordered: variant?.status?.isBackordered,
|
|
12
|
+
backorderedAvailableDate: variant?.status?.backorderedAvailableDate
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let isBackordered = false
|
|
17
|
+
let backorderedAvailableDate = null
|
|
18
|
+
if (variant?.type === 'kit') {
|
|
19
|
+
try {
|
|
20
|
+
/* eslint-disable no-unsafe-optional-chaining */
|
|
21
|
+
const latestBODate = Math.max(
|
|
22
|
+
...variant?.requiredProducts?.flatMap((a) =>
|
|
23
|
+
a?.product?.variants?.map(
|
|
24
|
+
(s) =>
|
|
25
|
+
Number(
|
|
26
|
+
new Date(s?.status?.backorderedAvailableDate)
|
|
27
|
+
) || 0
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
if (latestBODate) {
|
|
32
|
+
isBackordered = true
|
|
33
|
+
backorderedAvailableDate = moment(
|
|
34
|
+
new Date(latestBODate)
|
|
35
|
+
).format(dateFormat)
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
backorderedAvailableDate = null
|
|
39
|
+
}
|
|
40
|
+
} else if (variant?.type === 'bundle') {
|
|
41
|
+
try {
|
|
42
|
+
const latestBODate = Math.max(
|
|
43
|
+
...variant?.requiredProducts?.flatMap(
|
|
44
|
+
(a) =>
|
|
45
|
+
Number(
|
|
46
|
+
new Date(
|
|
47
|
+
a?.product?.variants[0]?.status?.backorderedAvailableDate
|
|
48
|
+
)
|
|
49
|
+
) || 0
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
if (latestBODate) {
|
|
53
|
+
isBackordered = true
|
|
54
|
+
backorderedAvailableDate = moment(
|
|
55
|
+
new Date(latestBODate)
|
|
56
|
+
).format(dateFormat)
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
backorderedAvailableDate = null
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
// changed
|
|
64
|
+
status: variant?.status?.status,
|
|
65
|
+
isBackordered: isBackordered,
|
|
66
|
+
backorderedAvailableDate: backorderedAvailableDate
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
5
70
|
const parsePrice = (product = []) => {
|
|
6
71
|
const requiredProducts = !isNullOrEmpty(product)
|
|
7
72
|
? product?.map((p) => p?.requiredProducts).flat()
|
|
@@ -90,49 +155,36 @@ const parsePrice = (product = []) => {
|
|
|
90
155
|
return sumOfPriceAndPoints
|
|
91
156
|
}
|
|
92
157
|
|
|
93
|
-
const
|
|
94
|
-
const dateFormat = 'YYYY-MM-DD'
|
|
95
|
-
let maxQty = null;
|
|
96
|
-
let backOrderedQty = null;
|
|
97
|
-
let availableQty = null;
|
|
98
|
-
let quantities = [];
|
|
99
|
-
let availableQuantities = [];
|
|
100
|
-
let prodQty = 0;
|
|
101
|
-
let dates = [];
|
|
102
|
-
let latestBackOrderedDate = null;
|
|
158
|
+
const parseKitAvailableQuantity = (kit) => {
|
|
103
159
|
try {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
} catch
|
|
124
|
-
console.
|
|
125
|
-
|
|
126
|
-
backOrderedQty = 0;
|
|
127
|
-
availableQty = 0;
|
|
128
|
-
latestBackOrderedDate = null;
|
|
160
|
+
return (
|
|
161
|
+
Math.min(
|
|
162
|
+
...kit.flatMap((a) =>
|
|
163
|
+
a?.sku?.map((s) => s?.inventoryProperties?.atpQty)
|
|
164
|
+
)
|
|
165
|
+
) || 0
|
|
166
|
+
)
|
|
167
|
+
} catch {
|
|
168
|
+
return 0
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const parseBundleAvailableQuantity = (product) => {
|
|
173
|
+
try {
|
|
174
|
+
const { requiredProducts = [] } = !isNullOrEmpty(product) ? product : {}
|
|
175
|
+
const quantities = requiredProducts?.map((p) =>
|
|
176
|
+
p?.product?.variants?.map((a) => a?.availableQuantity)
|
|
177
|
+
)
|
|
178
|
+
return Math.min(...quantities) || 0
|
|
179
|
+
} catch {
|
|
180
|
+
console.log('some error in availableQuantity')
|
|
181
|
+
return 0
|
|
129
182
|
}
|
|
130
|
-
return {status: bundle?.status?.status, maxQty, backOrderedQty, availableQty, latestBackOrderedDate}
|
|
131
183
|
}
|
|
132
184
|
|
|
133
|
-
const parseKit = (
|
|
185
|
+
const parseKit = (product, market) => {
|
|
134
186
|
const kits = {}
|
|
135
|
-
const [properties] = !isNullOrEmpty(
|
|
187
|
+
const [properties] = !isNullOrEmpty(product) ? product : []
|
|
136
188
|
kits.id = properties?.id
|
|
137
189
|
if (properties?.type === 'kit' && properties?.legacy_sku) {
|
|
138
190
|
kits.id = properties?.legacy_sku
|
|
@@ -147,7 +199,8 @@ const parseKit = (bundle, market) => {
|
|
|
147
199
|
kits.excludeFromSearch = isTrue(properties?.excludeFromSearch)
|
|
148
200
|
kits.isExclusive = isTrue(properties?.isExclusive)
|
|
149
201
|
kits.marketAttributes = properties?.marketAttributes
|
|
150
|
-
|
|
202
|
+
kits.maxQuantity = (product?.inventoryProperties || {}).atpQty
|
|
203
|
+
const priceData = parsePrice(product)
|
|
151
204
|
kits.points = priceData?.points
|
|
152
205
|
kits.price = priceData?.price
|
|
153
206
|
kits.purchaseTypes = {
|
|
@@ -165,27 +218,35 @@ const parseKit = (bundle, market) => {
|
|
|
165
218
|
kits.scanQualifiedCount = properties?.scanQualifiedCount
|
|
166
219
|
kits.foreignOrderLimit = properties?.foreignOrderLimit || properties?.foreign_limit
|
|
167
220
|
kits.taxClass = properties?.taxClass
|
|
221
|
+
// newVariant.slug = undefined
|
|
222
|
+
kits.status = parseStatus(properties)
|
|
223
|
+
if ((kits?.status || {})?.status === 'active')
|
|
224
|
+
kits.status.status = 'sellable'
|
|
168
225
|
const kitProducts = []
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
226
|
+
if (properties?.type === 'kit' && product?.kit) {
|
|
227
|
+
kits.type = 'kit'
|
|
228
|
+
kits.availableQuantity = parseKitAvailableQuantity(product?.kit)
|
|
229
|
+
for (const kit of product?.kit || []) {
|
|
230
|
+
const kitProduct = formatKit(kit, market)
|
|
231
|
+
kitProduct.id = kit?.identifier
|
|
232
|
+
kitProducts.push({
|
|
233
|
+
product: kitProduct,
|
|
234
|
+
quantity: (kit?.properties || {})?.quantity || 0,
|
|
235
|
+
isMandatory: true
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
} else if (
|
|
239
|
+
properties?.type === 'bundle' ||
|
|
240
|
+
(properties?.type === 'kit' && properties?.requiredProducts)
|
|
241
|
+
) {
|
|
242
|
+
kits.type = properties?.type
|
|
243
|
+
kits.availableQuantity = parseBundleAvailableQuantity(properties)
|
|
185
244
|
for (const kit of properties?.requiredProducts || []) {
|
|
186
245
|
if (kit?.product) {
|
|
246
|
+
const kitProduct = formatKit(kit?.product, market)
|
|
247
|
+
kitProduct.id = kit?.product?.id
|
|
187
248
|
kitProducts?.push({
|
|
188
|
-
product:
|
|
249
|
+
product: kitProduct,
|
|
189
250
|
quantity: kit?.quantity || 0,
|
|
190
251
|
isMandatory: true
|
|
191
252
|
})
|
|
@@ -193,24 +254,17 @@ const parseKit = (bundle, market) => {
|
|
|
193
254
|
}
|
|
194
255
|
for (const kit of properties?.optionalProducts || []) {
|
|
195
256
|
if (kit?.product) {
|
|
257
|
+
const kitProduct = formatKit(kit?.product, market)
|
|
258
|
+
kitProduct.id = kit?.product?.id
|
|
196
259
|
kitProducts?.push({
|
|
197
|
-
product:
|
|
260
|
+
product: kitProduct,
|
|
198
261
|
quantity: kit?.quantity || 0,
|
|
199
262
|
isMandatory: false
|
|
200
263
|
})
|
|
201
264
|
}
|
|
202
265
|
}
|
|
203
|
-
} else if (type === 'kit') {
|
|
204
|
-
for (const kit of properties?.requiredProducts || []) {
|
|
205
|
-
kitProducts.push({
|
|
206
|
-
product: formatKit(kit?.product, market),
|
|
207
|
-
quantity: kit?.quantity || 0,
|
|
208
|
-
isMandatory: true
|
|
209
|
-
})
|
|
210
|
-
}
|
|
211
266
|
}
|
|
212
267
|
kits.kitProducts = kitProducts
|
|
213
|
-
if ((kits?.status || {})?.status === 'active') kits.status.status = 'sellable'
|
|
214
268
|
return kits
|
|
215
269
|
}
|
|
216
270
|
|
|
@@ -223,7 +277,6 @@ const formatKit = (product, market) => {
|
|
|
223
277
|
if (['kit', 'bundle'].includes(product?.type)) {
|
|
224
278
|
kit = parseKit(product?.bundle, market)
|
|
225
279
|
}
|
|
226
|
-
|
|
227
280
|
return {
|
|
228
281
|
...product,
|
|
229
282
|
bundle: kit
|
|
@@ -232,5 +285,9 @@ const formatKit = (product, market) => {
|
|
|
232
285
|
|
|
233
286
|
module.exports = {
|
|
234
287
|
formatKit,
|
|
235
|
-
parseKit
|
|
288
|
+
parseKit,
|
|
289
|
+
parseBundleAvailableQuantity,
|
|
290
|
+
parseKitAvailableQuantity,
|
|
291
|
+
parsePrice,
|
|
292
|
+
parseStatus
|
|
236
293
|
}
|
package/src/formatVariant.js
CHANGED
|
@@ -2,121 +2,110 @@ const helpers = require('./helpers')
|
|
|
2
2
|
const _ = require('lodash')
|
|
3
3
|
const entities = require('entities')
|
|
4
4
|
|
|
5
|
-
const formatVariant = (parent) => {
|
|
6
|
-
const isBackOrdered = _.get(parent, 'defaults.status.backordered', null);
|
|
7
|
-
const backOrderedDate = _.get(parent, 'defaults.status.backorderedAvailableDate', null);
|
|
8
|
-
const preliminaryAvailableQty = _.get(parent, 'defaults.status.availableQuantity', 0);
|
|
9
|
-
const availableQty = isBackOrdered ? 0 : preliminaryAvailableQty;
|
|
10
|
-
const backOrderedQty = isBackOrdered ? preliminaryAvailableQty : 0;
|
|
11
|
-
let inventoryStatus = 'inStock';
|
|
12
|
-
if (isBackOrdered) {
|
|
13
|
-
inventoryStatus = 'backordered'
|
|
14
|
-
} else if (availableQty + backOrderedQty < 1) {
|
|
15
|
-
inventoryStatus = 'outOfStock';
|
|
16
|
-
}
|
|
17
|
-
|
|
5
|
+
const formatVariant = (parent) => ({
|
|
18
6
|
// Each value is a function with a parameter 'parent' that is the current instance of a Variant
|
|
19
7
|
// ContentStack references need to be queried separately
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
description
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
8
|
+
id: parent?.uid,
|
|
9
|
+
globalId: parent?.sap_data?.global_id,
|
|
10
|
+
sku: helpers?.getBestSkuData(parent)?.sku,
|
|
11
|
+
slug: parent?.slug,
|
|
12
|
+
size: parent?.size,
|
|
13
|
+
variantLabel: parent?.select_label,
|
|
14
|
+
variantColor: parent?.select_color,
|
|
15
|
+
title: parent?.name || parent?.defaults?.name,
|
|
16
|
+
salesLabel: parent?.sales_label,
|
|
17
|
+
salesText: parent?.sales_text,
|
|
18
|
+
activeEventDisclaimer: helpers?.mapActiveEventDisclaimer(parent?.active_event_disclaimer),
|
|
19
|
+
description: entities?.decodeHTML(
|
|
20
|
+
parent?.short_description_override || parent?.defaults?.description || ''
|
|
21
|
+
),
|
|
22
|
+
salesDisclaimer: helpers?.mapSalesDisclaimer(parent?.sales_disclaimer),
|
|
23
|
+
nettoWeight: parent?.netto_weight,
|
|
24
|
+
productImages: helpers?.mapProductImages(parent),
|
|
25
|
+
isExclusive: parent?.is_exclusive,
|
|
26
|
+
pricingJson: JSON.stringify(parent?.defaults?.status?.pricing) || null,
|
|
27
|
+
price: helpers?.mapPrice(parent),
|
|
28
|
+
points: helpers?.mapPoints(parent),
|
|
29
|
+
availableQuantity: _.get(parent, 'defaults.status.availableQuantity', 0),
|
|
30
|
+
maxQuantity: _.get(parent, 'defaults.status.maxQuantity', 0),
|
|
31
|
+
status: {
|
|
32
|
+
status: _.get(parent, 'defaults.status.status.retail', null),
|
|
33
|
+
retail: _.get(parent, 'defaults.status.status.retail', null),
|
|
34
|
+
wholesale: _.get(parent, 'defaults.status.status.wholesale', null),
|
|
35
|
+
isBackordered: _.get(parent, 'defaults.status.backordered', null),
|
|
36
|
+
backorderedAvailableDate: _.get(
|
|
37
|
+
parent,
|
|
38
|
+
'defaults.status.backorderedAvailableDate',
|
|
39
|
+
''
|
|
40
|
+
)
|
|
41
|
+
},
|
|
42
|
+
csStatus: helpers?.mapCsStatus(parent),
|
|
43
|
+
purchaseTypes: helpers?.mapPurchaseTypes(parent),
|
|
44
|
+
features: helpers?.mapFeatures(parent),
|
|
45
|
+
productDetails: helpers?.mapProductDetails(parent),
|
|
46
|
+
ingredients: helpers?.mapIngredients(
|
|
47
|
+
parent.ingredients_override,
|
|
48
|
+
parent.legacy_ingredients
|
|
49
|
+
),
|
|
50
|
+
benefitsAndFeatures: helpers?.mapBenefitsAndFeatures(parent),
|
|
51
|
+
results: helpers?.mapResults(parent),
|
|
52
|
+
usage: helpers?.mapUsage(parent, parent.legacy_usage),
|
|
53
|
+
resources: helpers?.mapResources(parent),
|
|
54
|
+
faqs: helpers?.mapFaqs(parent),
|
|
55
|
+
disclaimers: parent?.disclaimers || [],
|
|
56
|
+
disclaimerWarnings: helpers?.mapDisclaimerWarnings(
|
|
57
|
+
parent.disclaimer_warnings
|
|
58
|
+
),
|
|
59
|
+
matchingVariant:
|
|
60
|
+
parent.sap_data?.sku_data?.findIndex((s) =>
|
|
61
|
+
parent.searchedSkus.includes(s.sku)
|
|
62
|
+
) > -1,
|
|
63
|
+
shadeable: parent?.shadeable || false,
|
|
64
|
+
restrictedMarkets: parent?.restricted_markets || [],
|
|
65
|
+
productType: parent?.sap_data?.product_type,
|
|
66
|
+
primaryBrand: parent.sap_data?.primary_brand,
|
|
67
|
+
brandFamily: parent?.sap_data?.brand_family,
|
|
68
|
+
marketAttributes: {
|
|
69
|
+
discount: _.get(
|
|
70
|
+
parent,
|
|
71
|
+
'defaults.status.marketAttributes.discount',
|
|
72
|
+
null
|
|
59
73
|
),
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
version: parent._version || 0,
|
|
96
|
-
updatedAt: parent.updated_at || '',
|
|
97
|
-
updatedBy: parent.updated_by || '',
|
|
98
|
-
createdAt: parent.created_at || '',
|
|
99
|
-
createdBy: parent.created_by || '',
|
|
100
|
-
locale: parent.locale || ''
|
|
101
|
-
},
|
|
102
|
-
searchKeywords: parent?.search_keywords,
|
|
103
|
-
excludeFromSearch: parent?.exclude_from_search || helpers?.mapCsStatus(parent).status === 'discontinued' || _.get(parent, 'defaults.status.status.retail', null) === 'DISCONTINUED',
|
|
104
|
-
customerTypes: helpers?.getBestSkuData(parent)?.status_selections
|
|
105
|
-
?.customer_types,
|
|
106
|
-
availableChannels: helpers?.getBestSkuData(parent)?.status_selections
|
|
107
|
-
?.display_channels,
|
|
108
|
-
displayChannels: helpers?.getBestSkuData(parent)?.status_selections
|
|
109
|
-
?.display_channels,
|
|
110
|
-
scanQualifiedCount: helpers?.getBestSkuData(parent)?.scan_qualify_count,
|
|
111
|
-
scanQualifyCount: helpers?.getBestSkuData(parent)?.scan_qualify_count,
|
|
112
|
-
chargeShipping: helpers?.getBestSkuData(parent)?.charge_shipping,
|
|
113
|
-
dangerousGoods: helpers?.getBestSkuData(parent)?.dangerous_goods,
|
|
114
|
-
channels: helpers?.getBestSkuData(parent)?.channels,
|
|
115
|
-
foreignLimit: helpers?.getBestSkuData(parent)?.foreign_limit,
|
|
116
|
-
foreignOrderLimit: helpers?.getBestSkuData(parent)?.foreign_limit,
|
|
117
|
-
orderType: parent.sap_data?.order_type
|
|
118
|
-
}
|
|
119
|
-
}
|
|
74
|
+
redeem: _.get(parent, 'defaults.status.marketAttributes.redeem', null),
|
|
75
|
+
earn: _.get(parent, 'defaults.status.marketAttributes.earn', null)
|
|
76
|
+
},
|
|
77
|
+
legacyBenefits: parent.legacy_benefits,
|
|
78
|
+
legacyLongDescription: parent.legacy_long_description,
|
|
79
|
+
legacyResources: parent.legacy_resources,
|
|
80
|
+
legacyUsage: parent.legacy_usage,
|
|
81
|
+
legacyIngredients: parent.legacy_ingredients,
|
|
82
|
+
legacyImages: parent.legacy_images || [],
|
|
83
|
+
legacyYouTube: parent.legacy_youtube_video,
|
|
84
|
+
csAtts: {
|
|
85
|
+
version: parent._version || 0,
|
|
86
|
+
updatedAt: parent.updated_at || '',
|
|
87
|
+
updatedBy: parent.updated_by || '',
|
|
88
|
+
createdAt: parent.created_at || '',
|
|
89
|
+
createdBy: parent.created_by || '',
|
|
90
|
+
locale: parent.locale || ''
|
|
91
|
+
},
|
|
92
|
+
searchKeywords: parent?.search_keywords,
|
|
93
|
+
excludeFromSearch: parent?.exclude_from_search || helpers?.mapCsStatus(parent).status === 'discontinued' || _.get(parent, 'defaults.status.status.retail', null) === 'DISCONTINUED',
|
|
94
|
+
customerTypes: helpers?.getBestSkuData(parent)?.status_selections
|
|
95
|
+
?.customer_types,
|
|
96
|
+
availableChannels: helpers?.getBestSkuData(parent)?.status_selections
|
|
97
|
+
?.display_channels,
|
|
98
|
+
displayChannels: helpers?.getBestSkuData(parent)?.status_selections
|
|
99
|
+
?.display_channels,
|
|
100
|
+
scanQualifiedCount: helpers?.getBestSkuData(parent)?.scan_qualify_count,
|
|
101
|
+
scanQualifyCount: helpers?.getBestSkuData(parent)?.scan_qualify_count,
|
|
102
|
+
chargeShipping: helpers?.getBestSkuData(parent)?.charge_shipping,
|
|
103
|
+
dangerousGoods: helpers?.getBestSkuData(parent)?.dangerous_goods,
|
|
104
|
+
channels: helpers?.getBestSkuData(parent)?.channels,
|
|
105
|
+
foreignLimit: helpers?.getBestSkuData(parent)?.foreign_limit,
|
|
106
|
+
foreignOrderLimit: helpers?.getBestSkuData(parent)?.foreign_limit,
|
|
107
|
+
orderType: parent.sap_data?.order_type
|
|
108
|
+
})
|
|
120
109
|
|
|
121
110
|
module.exports = {
|
|
122
111
|
formatVariant
|
package/src/productStatus.js
CHANGED
|
@@ -45,7 +45,6 @@ async function getProductStatus(skus, locale, homeUrl, awsBase, clientId) {
|
|
|
45
45
|
const overrideMaxQuantity = marketConfig.skuMaxQty
|
|
46
46
|
? marketConfig.skuMaxQty[skus[i]]
|
|
47
47
|
: undefined
|
|
48
|
-
// @TODO - Update this code when we update our config for minimum availableQuantity in CS
|
|
49
48
|
const availableQuantity =
|
|
50
49
|
productStatus.availableQuantity < 999
|
|
51
50
|
? productStatus.availableQuantity
|