@nuskin/cs-product-lib 1.0.24-cx12-8656.1 → 1.0.24
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 +1 -4
- package/src/formatKit.js +52 -92
- package/src/formatVariant.js +6 -4
- package/src/productStatus.js +0 -1
package/package.json
CHANGED
package/src/csProduct.js
CHANGED
|
@@ -132,9 +132,6 @@ const csProduct = (props) => {
|
|
|
132
132
|
validVariants.push({
|
|
133
133
|
...variant,
|
|
134
134
|
status: varStatus,
|
|
135
|
-
backorderQuantity: varStatus?.backordered ? varStatus?.availableQuantity : 0,
|
|
136
|
-
availableQuantity: varStatus?.backordered ? 0 : varStatus?.availableQuantity,
|
|
137
|
-
backorderedAvailableDate: varStatus?.backorderedAvailableDate || null,
|
|
138
135
|
marketData
|
|
139
136
|
})
|
|
140
137
|
}
|
|
@@ -471,7 +468,7 @@ const csProduct = (props) => {
|
|
|
471
468
|
const translations = await getEntriesByQuery({
|
|
472
469
|
contentType: 'strings_product_detail_page',
|
|
473
470
|
locale,
|
|
474
|
-
includes: ['common_strings']
|
|
471
|
+
includes: ['common_strings', 'subscriptions.modal']
|
|
475
472
|
})
|
|
476
473
|
await parseSharedStrings(translations)
|
|
477
474
|
return translations
|
package/src/formatKit.js
CHANGED
|
@@ -16,40 +16,52 @@ const parseStatus = (variant) => {
|
|
|
16
16
|
let backorderedAvailableDate = null
|
|
17
17
|
if (variant?.type === 'kit') {
|
|
18
18
|
try {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
)
|
|
26
30
|
if (latestBODate) {
|
|
27
31
|
isBackordered = true
|
|
28
|
-
backorderedAvailableDate =
|
|
32
|
+
backorderedAvailableDate = moment(
|
|
33
|
+
new Date(latestBODate)
|
|
34
|
+
).format(dateFormat)
|
|
29
35
|
}
|
|
30
36
|
} catch {
|
|
31
37
|
backorderedAvailableDate = null
|
|
32
38
|
}
|
|
33
39
|
} else if (variant?.type === 'bundle') {
|
|
34
40
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
)
|
|
42
51
|
if (latestBODate) {
|
|
43
52
|
isBackordered = true
|
|
44
|
-
backorderedAvailableDate =
|
|
53
|
+
backorderedAvailableDate = moment(
|
|
54
|
+
new Date(latestBODate)
|
|
55
|
+
).format(dateFormat)
|
|
45
56
|
}
|
|
46
57
|
} catch {
|
|
47
58
|
backorderedAvailableDate = null
|
|
48
59
|
}
|
|
49
60
|
}
|
|
50
61
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
// changed
|
|
63
|
+
status: variant?.status?.status,
|
|
64
|
+
isBackordered: isBackordered,
|
|
53
65
|
backorderedAvailableDate: backorderedAvailableDate
|
|
54
66
|
}
|
|
55
67
|
}
|
|
@@ -142,85 +154,36 @@ const parsePrice = (product = []) => {
|
|
|
142
154
|
return sumOfPriceAndPoints
|
|
143
155
|
}
|
|
144
156
|
|
|
145
|
-
const parseKitAvailableQuantity = (
|
|
146
|
-
let quantities = [];
|
|
147
|
-
let prodQty = 0;
|
|
157
|
+
const parseKitAvailableQuantity = (kit) => {
|
|
148
158
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return Math.floor(maxAvailableQty);
|
|
159
|
-
} catch (error) {
|
|
160
|
-
return 0;
|
|
159
|
+
return (
|
|
160
|
+
Math.min(
|
|
161
|
+
...kit.flatMap((a) =>
|
|
162
|
+
a?.sku?.map((s) => s?.inventoryProperties?.atpQty)
|
|
163
|
+
)
|
|
164
|
+
) || 0
|
|
165
|
+
)
|
|
166
|
+
} catch {
|
|
167
|
+
return 0
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
170
|
|
|
164
171
|
const parseBundleAvailableQuantity = (product) => {
|
|
165
|
-
let quantities = [];
|
|
166
|
-
let prodQty = 0;
|
|
167
|
-
try {
|
|
168
|
-
product?.requiredProducts?.flatMap(a => {
|
|
169
|
-
prodQty = Number(a.quantity)
|
|
170
|
-
a?.product?.variants?.map(s => {
|
|
171
|
-
const backorderQty = s?.backorderQuantity/prodQty || 0;
|
|
172
|
-
const availableQty = s?.availableQuantity/prodQty || 0;
|
|
173
|
-
quantities.push({backorderQty, availableQty, canSellUpTo: Math.max(backorderQty, availableQty)})
|
|
174
|
-
})
|
|
175
|
-
})
|
|
176
|
-
const maxAvailableQty = quantities && quantities.length > 0 ? Math.min(...quantities.map(obj=>obj.canSellUpTo)) : 0;
|
|
177
|
-
return Math.floor(maxAvailableQty);
|
|
178
|
-
} catch (error) {
|
|
179
|
-
return 0;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const parseKitBackorderedQuantity = (skuKit) => {
|
|
185
|
-
let quantities = [];
|
|
186
|
-
let prodQty = 0;
|
|
187
172
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return Math.floor(maxBackorderedQty);
|
|
197
|
-
} catch (error) {
|
|
198
|
-
return 0;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const parseBundleBackorderedQuantity = (product) => {
|
|
203
|
-
let quantities = [];
|
|
204
|
-
let prodQty = 0;
|
|
205
|
-
try {
|
|
206
|
-
product?.requiredProducts?.flatMap(a => {
|
|
207
|
-
prodQty = Number(a?.quantity)
|
|
208
|
-
a?.product?.variants?.map(s => {
|
|
209
|
-
const backorderQty = s?.backorderQuantity/prodQty || 0;
|
|
210
|
-
quantities.push(backorderQty)
|
|
211
|
-
})
|
|
212
|
-
})
|
|
213
|
-
const maxBackorderedQty = quantities && quantities.length > 0 ? Math.min(...quantities) : 0;
|
|
214
|
-
return Math.floor(maxBackorderedQty);
|
|
215
|
-
} catch (error) {
|
|
216
|
-
return 0;
|
|
173
|
+
const { requiredProducts = [] } = !isNullOrEmpty(product) ? product : {}
|
|
174
|
+
const quantities = requiredProducts?.map((p) =>
|
|
175
|
+
p?.product?.variants?.map((a) => a?.availableQuantity)
|
|
176
|
+
)
|
|
177
|
+
return Math.min(...quantities) || 0
|
|
178
|
+
} catch {
|
|
179
|
+
console.log('some error in availableQuantity')
|
|
180
|
+
return 0
|
|
217
181
|
}
|
|
218
182
|
}
|
|
219
183
|
|
|
220
184
|
const parseKit = (product, market) => {
|
|
221
185
|
const kits = {}
|
|
222
186
|
const [properties] = !isNullOrEmpty(product) ? product : []
|
|
223
|
-
const status = parseStatus(properties)
|
|
224
187
|
kits.id = properties?.id
|
|
225
188
|
kits.uid = properties?.uid
|
|
226
189
|
kits.title = properties?.title
|
|
@@ -250,14 +213,13 @@ const parseKit = (product, market) => {
|
|
|
250
213
|
kits.scanQualifiedCount = properties?.scanQualifiedCount
|
|
251
214
|
kits.taxClass = properties?.taxClass
|
|
252
215
|
// newVariant.slug = undefined
|
|
253
|
-
kits.status =
|
|
254
|
-
if ((kits?.status || {})?.status === 'active')
|
|
216
|
+
kits.status = parseStatus(properties)
|
|
217
|
+
if ((kits?.status || {})?.status === 'active')
|
|
218
|
+
kits.status.status = 'sellable'
|
|
255
219
|
const kitProducts = []
|
|
256
220
|
if (properties?.type === 'kit' && product?.kit) {
|
|
257
221
|
kits.type = 'kit'
|
|
258
|
-
kits.availableQuantity = parseKitAvailableQuantity(product
|
|
259
|
-
kits.backorderQuantity = parseKitBackorderedQuantity(product.kit)
|
|
260
|
-
kits.backorderedAvailableDate = status?.backorderedAvailableDate
|
|
222
|
+
kits.availableQuantity = parseKitAvailableQuantity(product?.kit)
|
|
261
223
|
for (const kit of product?.kit || []) {
|
|
262
224
|
const kitProduct = formatKit(kit, market)
|
|
263
225
|
kitProduct.id = kit?.identifier
|
|
@@ -273,8 +235,6 @@ const parseKit = (product, market) => {
|
|
|
273
235
|
) {
|
|
274
236
|
kits.type = properties?.type
|
|
275
237
|
kits.availableQuantity = parseBundleAvailableQuantity(properties)
|
|
276
|
-
kits.backorderQuantity = parseBundleBackorderedQuantity(properties)
|
|
277
|
-
kits.backorderedAvailableDate = status?.backorderedAvailableDate
|
|
278
238
|
for (const kit of properties?.requiredProducts || []) {
|
|
279
239
|
if (kit?.product) {
|
|
280
240
|
const kitProduct = formatKit(kit?.product, market)
|
package/src/formatVariant.js
CHANGED
|
@@ -25,16 +25,18 @@ const formatVariant = (parent) => ({
|
|
|
25
25
|
pricingJson: JSON.stringify(parent?.defaults?.status?.pricing) || null,
|
|
26
26
|
price: helpers?.mapPrice(parent),
|
|
27
27
|
points: helpers?.mapPoints(parent),
|
|
28
|
-
|
|
29
|
-
backorderQuantity: _.get(parent, 'defaults.status.backordered', null) ? _.get(parent, 'defaults.status.availableQuantity', 0) : 0,
|
|
30
|
-
availableQuantity: _.get(parent, 'defaults.status.backordered', null) ? 0 : _.get(parent, 'defaults.status.availableQuantity', 0),
|
|
28
|
+
availableQuantity: _.get(parent, 'defaults.status.availableQuantity', 0),
|
|
31
29
|
maxQuantity: _.get(parent, 'defaults.status.maxQuantity', 0),
|
|
32
30
|
status: {
|
|
33
31
|
status: _.get(parent, 'defaults.status.status.retail', null),
|
|
34
32
|
retail: _.get(parent, 'defaults.status.status.retail', null),
|
|
35
33
|
wholesale: _.get(parent, 'defaults.status.status.wholesale', null),
|
|
36
34
|
isBackordered: _.get(parent, 'defaults.status.backordered', null),
|
|
37
|
-
backorderedAvailableDate: _.get(
|
|
35
|
+
backorderedAvailableDate: _.get(
|
|
36
|
+
parent,
|
|
37
|
+
'defaults.status.backorderedAvailableDate',
|
|
38
|
+
''
|
|
39
|
+
)
|
|
38
40
|
},
|
|
39
41
|
csStatus: helpers?.mapCsStatus(parent),
|
|
40
42
|
purchaseTypes: helpers?.mapPurchaseTypes(parent),
|
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
|