@nuskin/cs-product-lib 1.0.9-cx12-6632.3 → 1.0.10
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/formatKit.js +14 -14
package/package.json
CHANGED
package/src/formatKit.js
CHANGED
|
@@ -59,7 +59,7 @@ const parsePrice = (product = []) => {
|
|
|
59
59
|
|
|
60
60
|
const variants = requiredProducts?.map(p => {
|
|
61
61
|
const [firstVariant] = p?.product?.variants || []
|
|
62
|
-
return firstVariant
|
|
62
|
+
return {...firstVariant, quantity: p?.quantity}
|
|
63
63
|
})
|
|
64
64
|
|
|
65
65
|
const defaultValues = {
|
|
@@ -84,29 +84,29 @@ const parsePrice = (product = []) => {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
// sum of price and points from 1st variant of product bundle
|
|
87
|
-
const
|
|
87
|
+
const sumOfPriceAndPoints = variants.reduce((acc, curr) => {
|
|
88
88
|
const price = {}
|
|
89
89
|
const points = {
|
|
90
90
|
subscription : {},
|
|
91
91
|
wholesale : {}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
price.retail = Number(acc?.price?.retail || 0) + Number(curr?.price?.retail || 0)
|
|
95
|
-
price.retailSubscription = Number(acc?.price?.retailSubscription || 0) + Number(curr?.price?.retailSubscription || 0)
|
|
96
|
-
price.wholesale = Number(acc?.price?.wholesale || 0) + Number(curr?.price?.wholesale || 0)
|
|
97
|
-
price.wholesaleSubscription = Number(acc?.price?.wholesaleSubscription || 0) + Number(curr?.price?.wholesaleSubscription || 0)
|
|
94
|
+
price.retail = Number((acc?.price?.retail || 0)) + Number((curr?.price?.retail || 0) * (curr?.quantity || 1))
|
|
95
|
+
price.retailSubscription = Number(acc?.price?.retailSubscription || 0) + Number((curr?.price?.retailSubscription || 0) * (curr?.quantity || 1))
|
|
96
|
+
price.wholesale = Number(acc?.price?.wholesale || 0) + Number((curr?.price?.wholesale || 0) * (curr?.quantity || 1))
|
|
97
|
+
price.wholesaleSubscription = Number(acc?.price?.wholesaleSubscription || 0) + Number((curr?.price?.wholesaleSubscription || 0) * (curr?.quantity || 1))
|
|
98
98
|
price.currencyCode = curr?.price.currencyCode
|
|
99
99
|
|
|
100
|
-
points.subscription.cv = Number(acc?.points?.subscription?.cv || 0) + Number(curr?.points?.subscription?.cv || 0)
|
|
101
|
-
points.subscription.pv = Number(acc?.points?.subscription?.pv || 0) + Number(curr?.points?.subscription?.pv || 0)
|
|
102
|
-
points.subscription.sb = Number(acc?.points?.subscription?.sb || 0) + Number(curr?.points?.subscription?.sb || 0)
|
|
103
|
-
points.wholesale.cv = Number(acc?.points?.wholesale?.cv || 0) + Number(curr?.points?.wholesale?.cv || 0)
|
|
104
|
-
points.wholesale.pv = Number(acc?.points?.wholesale?.pv || 0) + Number(curr?.points?.wholesale?.pv || 0)
|
|
105
|
-
points.wholesale.sb = Number(acc?.points?.wholesale?.sb || 0) + Number(curr?.points?.wholesale?.sb || 0)
|
|
100
|
+
points.subscription.cv = Number(acc?.points?.subscription?.cv || 0) + Number((curr?.points?.subscription?.cv || 0) * (curr?.quantity || 1))
|
|
101
|
+
points.subscription.pv = Number(acc?.points?.subscription?.pv || 0) + Number((curr?.points?.subscription?.pv || 0) * (curr?.quantity || 1))
|
|
102
|
+
points.subscription.sb = Number(acc?.points?.subscription?.sb || 0) + Number((curr?.points?.subscription?.sb || 0) * (curr?.quantity || 1))
|
|
103
|
+
points.wholesale.cv = Number(acc?.points?.wholesale?.cv || 0) + Number((curr?.points?.wholesale?.cv || 0) * (curr?.quantity || 1))
|
|
104
|
+
points.wholesale.pv = Number(acc?.points?.wholesale?.pv || 0) + Number((curr?.points?.wholesale?.pv || 0) * (curr?.quantity || 1))
|
|
105
|
+
points.wholesale.sb = Number(acc?.points?.wholesale?.sb || 0) + Number((curr?.points?.wholesale?.sb || 0) * (curr?.quantity || 1))
|
|
106
106
|
|
|
107
107
|
return { price, points}
|
|
108
108
|
}, defaultValues)
|
|
109
|
-
return
|
|
109
|
+
return sumOfPriceAndPoints
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
const parseKitAvailableQuantity = (kit) => {
|
|
@@ -120,7 +120,7 @@ const parseKitAvailableQuantity = (kit) => {
|
|
|
120
120
|
const parseBundleAvailableQuantity = (product) => {
|
|
121
121
|
try {
|
|
122
122
|
const {requiredProducts = []} = product|| {}
|
|
123
|
-
const quantities = requiredProducts
|
|
123
|
+
const quantities = requiredProducts.map(p=>p.product?.variants.map(a=>a.availableQuantity))
|
|
124
124
|
return Math.min(...quantities) || 0
|
|
125
125
|
} catch {
|
|
126
126
|
console.log("some error in availableQuantity")
|