summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-03-27 17:03:28 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-03-27 17:03:28 +0700
commita040418bdddd5fcaf8a8d67e0a66ea92fd16ee24 (patch)
tree22be75fe02bf75dfafa7c82b0eef2187b186f86a /src/lib
parent7ed2913450713655d2e962846d795dc6b4091de4 (diff)
-
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cart/components/Cart.jsx4
-rw-r--r--src/lib/checkout/components/Checkout.jsx23
2 files changed, 19 insertions, 8 deletions
diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx
index d646420c..7ebee14b 100644
--- a/src/lib/cart/components/Cart.jsx
+++ b/src/lib/cart/components/Cart.jsx
@@ -93,11 +93,11 @@ const Cart = () => {
quantity -= value
break
case 'BLUR':
- if (value != '') return
+ if (value != '' && value > 0) return
quantity = 1
break
default:
- quantity = value
+ quantity = value != '' && value < 1 ? 1 : value
break
}
productsToUpdate[productIndex].quantity = quantity
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}