summaryrefslogtreecommitdiff
path: root/src/lib/cart/components/Cart.jsx
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-03-27 15:17:59 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-03-27 15:17:59 +0700
commit7ed2913450713655d2e962846d795dc6b4091de4 (patch)
treef3f38ecde8dfc3514d6edc66a6f41f13868918bc /src/lib/cart/components/Cart.jsx
parent949a03f9a12b17fad85ecc58baad6352ba98d04d (diff)
cart
Diffstat (limited to 'src/lib/cart/components/Cart.jsx')
-rw-r--r--src/lib/cart/components/Cart.jsx13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index 8cd6df96..d646420c 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -14,6 +14,7 @@ import Spinner from '@/core/components/elements/Spinner/Spinner'
import Alert from '@/core/components/elements/Alert/Alert'
import MobileView from '@/core/components/views/MobileView'
import DesktopView from '@/core/components/views/DesktopView'
+import variantPriceApi from '@/lib/variant/api/variantPriceApi'
const Cart = () => {
const router = useRouter()
@@ -28,16 +29,24 @@ const Cart = () => {
useEffect(() => {
if (cart.data && !products) {
- const productsWithQuantity = cart.data.map((product) => {
+ const productsWithQuantity = cart.data.map(async (product) => {
const productInCart = getItemCart({ productId: product.id })
if (!productInCart) return
+ const productPrice = await variantPriceApi({ id: product.id })
return {
...product,
+ price: {
+ price: productPrice.priceExclude,
+ discountPercentage: productPrice.discount,
+ priceDiscount: productPrice.priceExcludeAfterDiscount
+ },
quantity: productInCart.quantity,
selected: productInCart.selected
}
})
- setProducts(productsWithQuantity)
+ Promise.all(productsWithQuantity).then((resolvedProducts) => {
+ setProducts(resolvedProducts)
+ })
}
}, [cart, products])