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