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 +++++++++++------- src/lib/checkout/components/Checkout.jsx | 194 ++++++++++++++++-------- src/lib/variant/components/VariantGroupCard.jsx | 67 +++++++- 3 files changed, 283 insertions(+), 127 deletions(-) (limited to 'src') 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 diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 09fdbd86..0eaab020 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -289,8 +289,8 @@ const Checkout = () => {
Grand Total
- {currencyFormat(cartCheckout?.grandTotal + - Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 + {currencyFormat( + cartCheckout?.grandTotal + Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 )}
@@ -398,73 +398,131 @@ const Checkout = () => { {products?.map((product) => ( - - -
- {product?.name} -
-
-
- {product?.parent?.name} -
-
- {product?.code}{' '} - {product?.attributes.length > 0 - ? `| ${product?.attributes.join(', ')}` - : ''} -
-
- Berat item : {product?.weight} Kg + <> + + +
+ {product?.name}
-
- - - - - - {product?.price?.discountPercentage > 0 && ( -
-
- {currencyFormat(product?.price?.price)} +
+
+ {product?.parent?.name}
-
- {product?.price?.discountPercentage}% +
+ {product?.code}{' '} + {product?.attributes.length > 0 + ? `| ${product?.attributes.join(', ')}` + : ''} +
+
+ Berat item : {product?.weight} Kg
- )} -
- {product.price.priceDiscount > 0 - ? currencyFormat(product?.price?.priceDiscount) - : 'Call For Price'} -
- - -
- {product.price.priceDiscount > 0 ? ( - currencyFormat(product?.price?.priceDiscount * product?.quantity) - ) : ( - - Call For Price{' '} - + + + + + + {product?.price?.discountPercentage > 0 && ( +
+
+ {currencyFormat(product?.price?.price)} +
+
+ {product?.price?.discountPercentage}% +
+
)} -
- - +
+ {product.price.priceDiscount > 0 + ? currencyFormat(product?.price?.priceDiscount) + : 'Call For Price'} +
+ + +
+ {product.price.priceDiscount > 0 ? ( + currencyFormat(product?.price?.priceDiscount * product?.quantity) + ) : ( + + Call For Price{' '} + + )} +
+ + + {product.program && + product.program.items && + product.program.items.map((item) => ( + <> + + +
+ {item.name} +
+
+
+ + {product.program.type.label} + +
+
+ {item.name} +
+
+ + + + + + {item?.price?.discountPercentage > 0 && ( +
+
+ {currencyFormat(product?.price?.price)} +
+
+ )} +
+ {item?.price.priceDiscount > 0 ? 'Gratis' : ''} +
+ + +
+ {item.price.priceDiscount > 0 ? 'Gratis' : ''} +
+ + + + + ))} + ))} @@ -487,7 +545,9 @@ const Checkout = () => {
Total Diskon
-
- {currencyFormat(cartCheckout?.totalDiscount)}
+
+ - {currencyFormat(cartCheckout?.totalDiscount)} +
Subtotal
@@ -511,8 +571,8 @@ const Checkout = () => {
Grand Total
- {currencyFormat(cartCheckout?.grandTotal + - Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 + {currencyFormat( + cartCheckout?.grandTotal + Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000 )}
diff --git a/src/lib/variant/components/VariantGroupCard.jsx b/src/lib/variant/components/VariantGroupCard.jsx index 8cb1eec4..aba6971f 100644 --- a/src/lib/variant/components/VariantGroupCard.jsx +++ b/src/lib/variant/components/VariantGroupCard.jsx @@ -1,14 +1,79 @@ import { useState } from 'react' import VariantCard from './VariantCard' +import Image from '@/core/components/elements/Image/Image' +import currencyFormat from '@/core/utils/currencyFormat' const VariantGroupCard = ({ variants, ...props }) => { + console.log('variant', variants) const [showAll, setShowAll] = useState(false) const variantsToShow = showAll ? variants : variants.slice(0, 2) return ( <> {variantsToShow?.map((variant, index) => ( - + <> + + {variant.program && + variant.program.items && + variant.program.items.map((item) => ( +
+
+
+ {item.name} +
+
+

+ {item.name} +

+

+ {/* {product.code || '-'} + {product.attributes.length > 0 ? ` ・ ${product.attributes.join(', ')}` : ''} */} +

+

+ Berat Item : {item.weight} Kg +

+
+ {item.price.discountPercentage > 0 && ( + <> +

+ {currencyFormat(item.price.price)} +

+ {item.price.discountPercentage}% + + )} +
+

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

+

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

+
+
+
+ ))} + ))} {variants.length > 2 && (