@nuskin/cs-product-lib 1.0.10 → 1.0.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/cs-product-lib",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Library for pulling and parsing product content (and applying business logic) retrieved from Contentstack",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/csProduct.js CHANGED
@@ -215,7 +215,7 @@ const csProduct = (props) => {
215
215
  const requiredProducts = []
216
216
  for (let i = 0; i < products.length; i++) {
217
217
  for (let v = 0; v < products[i].variants.length; v++) {
218
- if (products[i].variants[v].sku !== variantSkus[i]) {
218
+ if (!variantSkus.includes(products[i].variants[v].sku)) {
219
219
  products[i].variants.splice(v, 1)
220
220
  v--
221
221
  }
package/src/formatKit.js CHANGED
@@ -2,55 +2,43 @@ const moment = require('moment')
2
2
 
3
3
  const parseStatus = (variant) => {
4
4
  const dateFormat = 'YYYY-MM-DD'
5
- const properties = variant.properties || {}
6
- if (
7
- variant.inventoryProperties &&
8
- variant.inventoryProperties.backOrdered &&
9
- variant.inventoryProperties.expectedBackOrderAvailabilityDate) {
10
- return {
11
5
 
12
- // changed
13
- status: 'inactive',
14
- isBackordered: variant.inventoryProperties.backOrdered,
15
- backorderedAvailableDate: moment(variant.inventoryProperties.expectedBackOrderAvailabilityDate).format(dateFormat)
6
+ if (variant.type !== 'bundle' && variant.type !== 'kit') {
7
+ return {
8
+ status: variant.status.status,
9
+ isBackordered: variant.status.isBackordered,
10
+ backorderedAvailableDate: variant.status.backorderedAvailableDate
16
11
  }
17
- } else if(properties.productStatus) {
18
- let isBackordered = false
19
- let backorderedAvailableDate = null
20
- if (variant.kit) {
21
- try {
22
- const latestBODate = Math.min(...variant.kit.flatMap(a=>a.sku.map(s=>s.inventoryProperties.expectedBackOrderAvailabilityDate))) || 0
23
- if (latestBODate) {
24
- isBackordered = true
25
- backorderedAvailableDate = moment(Date(latestBODate)).format(dateFormat)
26
- }
27
- } catch {
28
- backorderedAvailableDate = null
29
- }
30
-
31
- } else if (variant.bundle) {
32
- try {
33
- const latestBODate = Math.min(...variant.bundleMandatoryProducts.flatMap(a=>a.sku.map(s=>s.inventoryProperties.expectedBackOrderAvailabilityDate))) || 0
34
- if (latestBODate) {
35
- isBackordered = true
36
- backorderedAvailableDate = moment(Date(latestBODate)).format(dateFormat)
37
- }
38
- } catch {
39
- backorderedAvailableDate = null
12
+ }
13
+
14
+ let isBackordered = false
15
+ let backorderedAvailableDate = null
16
+ if (variant.type === 'kit') {
17
+ try {
18
+ const latestBODate = Math.max(...variant.requiredProducts.flatMap(a=>a.product.variants.map(s=>Number(new Date(s.status.backorderedAvailableDate)) || 0)))
19
+ if (latestBODate) {
20
+ isBackordered = true
21
+ backorderedAvailableDate = moment(new Date(latestBODate)).format(dateFormat)
40
22
  }
23
+ } catch {
24
+ backorderedAvailableDate = null
41
25
  }
42
- return {
43
- // changed
44
- status: 'active',
45
- isBackordered,
46
- backorderedAvailableDate
26
+ } else if (variant.type === 'bundle') {
27
+ try {
28
+ const latestBODate = Math.max(...variant.requiredProducts.flatMap(a=>Number(new Date(a.product.variants[0]?.status?.backorderedAvailableDate)) || 0))
29
+ if (latestBODate) {
30
+ isBackordered = true
31
+ backorderedAvailableDate = moment(new Date(latestBODate)).format(dateFormat)
32
+ }
33
+ } catch {
34
+ backorderedAvailableDate = null
47
35
  }
48
- }
36
+ }
49
37
  return {
50
38
  // changed
51
- status: 'active',
52
- isBackordered: false,
53
- backorderedAvailableDate: null
39
+ status: variant.status.status,
40
+ isBackordered: isBackordered,
41
+ backorderedAvailableDate: backorderedAvailableDate
54
42
  }
55
43
  };
56
44
 
@@ -95,7 +83,7 @@ const parsePrice = (product = []) => {
95
83
  price.retailSubscription = Number(acc?.price?.retailSubscription || 0) + Number((curr?.price?.retailSubscription || 0) * (curr?.quantity || 1))
96
84
  price.wholesale = Number(acc?.price?.wholesale || 0) + Number((curr?.price?.wholesale || 0) * (curr?.quantity || 1))
97
85
  price.wholesaleSubscription = Number(acc?.price?.wholesaleSubscription || 0) + Number((curr?.price?.wholesaleSubscription || 0) * (curr?.quantity || 1))
98
- price.currencyCode = curr?.price.currencyCode
86
+ price.currencyCode = curr?.price?.currencyCode
99
87
 
100
88
  points.subscription.cv = Number(acc?.points?.subscription?.cv || 0) + Number((curr?.points?.subscription?.cv || 0) * (curr?.quantity || 1))
101
89
  points.subscription.pv = Number(acc?.points?.subscription?.pv || 0) + Number((curr?.points?.subscription?.pv || 0) * (curr?.quantity || 1))
@@ -159,7 +147,7 @@ const parseKit = (product, market) => {
159
147
  kits.grpDiscount = properties?.grpDiscount
160
148
  kits.scanQualifiedCount = properties?.scanQualifiedCount
161
149
  // newVariant.slug = undefined
162
- kits.status = parseStatus(product)
150
+ kits.status = parseStatus(properties)
163
151
  if ((kits.status || {}).status === 'active') kits.status.status = 'sellable'
164
152
  const kitProducts = []
165
153
  if (properties.type === 'kit' && product.kit) {