From 2413603c4e17c5ab2f3d07ec26c40f1d2f61bc67 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 11 Apr 2023 16:32:49 +0700 Subject: validate if price 0 --- src/lib/checkout/components/Checkout.jsx | 39 ++++++++++++++++++++++++++---- src/lib/variant/components/VariantCard.jsx | 12 +++++++-- 2 files changed, 44 insertions(+), 7 deletions(-) (limited to 'src/lib') diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index cb96b995..eee679fd 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -61,6 +61,7 @@ const Checkout = () => { const [products, setProducts] = useState(null) const [totalAmount, setTotalAmount] = useState(0) const [totalDiscountAmount, setTotalDiscountAmount] = useState(0) + const [priceCheck, setPriceCheck] = useState(false) useEffect(() => { const loadProducts = async () => { @@ -77,6 +78,7 @@ const Checkout = () => { const dataProducts = await CartApi({ variantIds }) const productsWithQuantity = dataProducts?.map((product) => { + if (product.price.priceDiscount == 0) setPriceCheck(true) return { ...product, quantity: query.quantity @@ -141,7 +143,6 @@ const Checkout = () => { setIsLoading(false) window.location.href = payment.data.redirectUrl } - const taxTotal = (totalAmount - totalDiscountAmount) * 0.11 return ( @@ -241,11 +242,21 @@ const Checkout = () => { + {priceCheck && ( +
+ + *) Terdapat produk yang belum memiliki harga,{' '} + + Hubungi Kami untuk meminta harga. + + +
+ )} @@ -309,12 +320,20 @@ const Checkout = () => { )}
- {currencyFormat(product?.price?.priceDiscount)} + {product.price.priceDiscount > 0 + ? currencyFormat(product?.price?.priceDiscount) + : 'Call For Price'}
- {currencyFormat(product?.price?.priceDiscount * product?.quantity)} + {product.price.priceDiscount > 0 ? ( + currencyFormat(product?.price?.priceDiscount * product?.quantity) + ) : ( + + Call For Price{' '} + + )}
@@ -396,10 +415,20 @@ const Checkout = () => { + {priceCheck && ( +
+ + *) Terdapat produk yang belum memiliki harga,{' '} + + Hubungi Kami untuk meminta harga. + + +
+ )} diff --git a/src/lib/variant/components/VariantCard.jsx b/src/lib/variant/components/VariantCard.jsx index 8161473d..8cd70bc0 100644 --- a/src/lib/variant/components/VariantCard.jsx +++ b/src/lib/variant/components/VariantCard.jsx @@ -49,10 +49,18 @@ const VariantCard = ({ product, openOnClick = true, buyMore = false }) => { )}

- {currencyFormat(product.price.priceDiscount)} × {product.quantity} Barang + {product.price.priceDiscount > 0 + ? currencyFormat(product.price.priceDiscount) + ' × ' + product.quantity + ' Barang' + : ''}

- {currencyFormat(product.quantity * product.price.priceDiscount)} + {product.price.priceDiscount > 0 ? ( + currencyFormat(product.quantity * product.price.priceDiscount) + ) : ( + + Call For Price{' '} + + )}

-- cgit v1.2.3