From 8b173abd19630b7cab5f0f562925c46e3f71d096 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 4 Jul 2023 13:38:33 +0700 Subject: promotion program --- src/lib/cart/components/Cart.jsx | 149 +++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 59 deletions(-) (limited to 'src/lib/cart') diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index 45f2f770..f1584f98 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -59,7 +59,8 @@ const Cart = () => { ) setProducts(updatedProducts) } - processProducts() + // processProducts() + setProducts(cart.products) setIsLoading(false) } }, [cart]) @@ -86,6 +87,10 @@ const Cart = () => { if (product.quantity == '') continue if (!product.selected) continue + + if (product.canBuy == false) { + toggleSelected(product.id) + } let priceBeforeTax = product.price.price / 1.11 calculateTotalPriceBeforeTax += priceBeforeTax * product.quantity calculateTotalTaxAmount += (product.price.price - priceBeforeTax) * product.quantity @@ -153,7 +158,12 @@ const Cart = () => { productsToUpdate[productIndex].quantity = qty setProducts([...productsToUpdate]) - addCart(productId, qty, productsToUpdate[productIndex].selected) + addCart( + productId, + qty, + productsToUpdate[productIndex].selected, + productsToUpdate[productIndex].program?.id + ) } const toggleSelected = (productId) => { @@ -165,7 +175,12 @@ const Cart = () => { productsToUpdate[productIndex].selected = isSelected setProducts([...productsToUpdate]) - addCart(productId, productsToUpdate[productIndex].quantity, isSelected) + addCart( + productId, + productsToUpdate[productIndex].quantity, + isSelected, + productsToUpdate[productIndex].program?.id + ) } const selectedProduct = () => { @@ -259,7 +274,7 @@ const Cart = () => { {products && products?.map((product) => ( <> - {product.isPromo > 0 && ( + {product.hasProgram > 0 && (
{product.program ? ( <> @@ -470,7 +485,7 @@ const Cart = () => { {products && products?.map((product) => ( <> - {product.isPromo > 0 && ( + {product.hasProgram && (
@@ -489,7 +504,7 @@ const Cart = () => { Selamat! Pembelian anda lebih hemat {' '} - {currencyFormat(product.program.price.priceDiscount)} + {currencyFormat(product.program?.totalSavings)} )} @@ -539,9 +554,10 @@ const Cart = () => { )} - + + toggleSelected(product.id)} @@ -549,7 +565,8 @@ const Cart = () => { className='accent-danger-500 w-4' /> - + + {
- + + { onBlur={(e) => updateQuantity(e.target.value, product?.id, 'BLUR')} /> - + + {product?.price?.discountPercentage > 0 && (
@@ -607,7 +626,8 @@ const Cart = () => { {currencyFormat(product?.price?.priceDiscount)}
- + +
{currencyFormat(product?.price?.priceDiscount * product?.quantity)}
@@ -623,54 +643,62 @@ const Cart = () => {
- {product.program && ( - - - -
- {product.program.name} -
-
-
- - {product.program.type.label} - -
-
- {product.program.name} -
-
- - - - - - {product?.price?.discountPercentage > 0 && ( -
-
- {currencyFormat(product?.price?.price)} + {product?.program?.items && ( + + {product.program.items.map((item) => ( + <> + + + + + +
+ {item.name}
-
- )} -
- {product?.program?.price.priceDiscount > 0 ? 'Gratis' : ''} -
- - -
- {product.program.price.priceDiscount > 0 ? 'Gratis' : ''} -
- - +
+
+ + {product.program.type.label} + +
+
{item.name}
+
+ + + + + + + + {item?.price?.discountPercentage > 0 && ( +
+
+ {currencyFormat(product?.price?.price)} +
+
+ )} +
+ {item?.price.priceDiscount > 0 ? 'Gratis' : ''} +
+ + + +
+ {item.price.priceDiscount > 0 ? 'Gratis' : ''} +
+ + + + ))} )} @@ -747,4 +775,7 @@ const Cart = () => { ) } +const ComponentCanBuy = ({ canBuy }) => + !canBuy &&
+ export default Cart -- cgit v1.2.3