From a040418bdddd5fcaf8a8d67e0a66ea92fd16ee24 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Mon, 27 Mar 2023 17:03:28 +0700
Subject: -

---
 src/lib/checkout/components/Checkout.jsx | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

(limited to 'src/lib/checkout/components/Checkout.jsx')

diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 57d217a7..048bb24e 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -19,6 +19,7 @@ import axios from 'axios'
 import Image from '@/core/components/elements/Image/Image'
 import MobileView from '@/core/components/views/MobileView'
 import DesktopView from '@/core/components/views/DesktopView'
+import variantPriceApi from '@/lib/variant/api/variantPriceApi'
 
 const Checkout = () => {
   const router = useRouter()
@@ -77,11 +78,21 @@ const Checkout = () => {
       }
 
       const dataProducts = await CartApi({ variantIds })
-      const dataProductsQuantity = _.map(dataProducts, (o) => ({
-        ...o,
-        quantity: query.quantity ? query.quantity : getItemCart({ productId: o.id }).quantity
-      }))
-      setProducts(dataProductsQuantity)
+      const productsWithQuantity = dataProducts.map(async (product) => {
+        const productPrice = await variantPriceApi({ id: product.id })
+        return {
+          ...product,
+          price: {
+            price: productPrice.priceExclude,
+            discountPercentage: productPrice.discount,
+            priceDiscount: productPrice.priceExcludeAfterDiscount
+          },
+          quantity: query.quantity ? query.quantity : getItemCart({ productId: product.id }).quantity
+        }
+      })
+      Promise.all(productsWithQuantity).then((resolvedProducts) => {
+        setProducts(resolvedProducts)
+      })
     }
     loadProducts()
   }, [router])
@@ -439,7 +450,7 @@ const Checkout = () => {
               <p className='text-caption-2 text-gray_r-11 mt-2'>Ukuran dokumen PO Maksimal 5MB</p>
 
               <hr className='my-4 border-gray_r-6' />
-              
+
               <button
                 className='w-full btn-yellow mt-4'
                 onClick={checkout}
-- 
cgit v1.2.3

