From d868fa4283ea5c37eb08b998140965f70083fe0b Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 15 Dec 2022 17:26:59 +0700 Subject: Show detail if cart product > 0 --- src/pages/shop/cart.js | 116 ++++++++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/pages/shop/cart.js b/src/pages/shop/cart.js index 16734065..6f61ffcb 100644 --- a/src/pages/shop/cart.js +++ b/src/pages/shop/cart.js @@ -41,23 +41,24 @@ export default function Cart() { useEffect(() => { const productsToProcess = products.filter((product) => product.to_process == true); - if (products.length > 0) { - - let calculateTotalPriceBeforeTax = 0; - let calculateTotalTaxAmount = 0; - let calculateTotalDiscountAmount = 0; - productsToProcess.forEach(product => { - let priceBeforeTax = product.price.price / 1.11; - calculateTotalPriceBeforeTax += priceBeforeTax * product.quantity; - calculateTotalTaxAmount += (product.price.price - priceBeforeTax) * product.quantity; - calculateTotalDiscountAmount += (product.price.price - product.price.price_discount) * product.quantity; - }); - setTotalPriceBeforeTax(calculateTotalPriceBeforeTax); - setTotalTaxAmount(calculateTotalTaxAmount); - setTotalDiscountAmount(calculateTotalDiscountAmount); - } + let calculateTotalPriceBeforeTax = 0; + let calculateTotalTaxAmount = 0; + let calculateTotalDiscountAmount = 0; + productsToProcess.forEach(product => { + let priceBeforeTax = product.price.price / 1.11; + calculateTotalPriceBeforeTax += priceBeforeTax * product.quantity; + calculateTotalTaxAmount += (product.price.price - priceBeforeTax) * product.quantity; + calculateTotalDiscountAmount += (product.price.price - product.price.price_discount) * product.quantity; + }); + setTotalPriceBeforeTax(calculateTotalPriceBeforeTax); + setTotalTaxAmount(calculateTotalTaxAmount); + setTotalDiscountAmount(calculateTotalDiscountAmount); }, [products]); + const getProductsToProcess = () => { + return products.filter((product) => product.to_process == true); + } + const updateCart = (productId, quantity) => { let productIndexToUpdate = products.findIndex((product) => product.id == productId); if (quantity != '') createOrUpdateItemCart(productId, quantity); @@ -134,12 +135,10 @@ export default function Cart() {
{/* [Start] Title */} -
- - - -

Keranjang Saya

-
+ + +

Keranjang Saya

+ {/* [End] Title */} {/* [Start] Product List */} @@ -148,7 +147,7 @@ export default function Cart() {
@@ -203,40 +202,59 @@ export default function Cart() { {/* [End] Product List */} {/* [Start] Review Order */} -
-

Ringkasan Pesanan

-
-
-
-

Harga Sebelum PPN

-

{currencyFormat(totalPriceBeforeTax)}

+ {products.length > 0 ? ( +
+
+

Ringkasan Pesanan

+ {getProductsToProcess().length > 0 ? ( +

{getProductsToProcess().length} Barang

+ ) : ''}
-
-

PPN 11%

-

{currencyFormat(totalTaxAmount)}

+
+
+
+

Subtotal

+

{currencyFormat(totalPriceBeforeTax)}

+
+
+

PPN 11%

+

{currencyFormat(totalTaxAmount)}

+
+
+

Total Diskon

+

- {currencyFormat(totalDiscountAmount)}

+
-
-

Total Diskon

-

- {currencyFormat(totalDiscountAmount)}

+
+
+

Total

+

{currencyFormat(totalPriceBeforeTax + totalTaxAmount - totalDiscountAmount)}

+

*) Belum termasuk biaya pengiriman

+

+ Dengan melakukan pembelian melalui website Indoteknik, saya menyetujui Syarat & Ketentuan yang berlaku +

-
-
-

Total Harga

-

{currencyFormat(totalPriceBeforeTax + totalTaxAmount - totalDiscountAmount)}

-
-

*) Belum termasuk biaya pengiriman

-

- Dengan melakukan pembelian melalui website Indoteknik, saya menyetujui Syarat & Ketentuan yang berlaku -

-
+ ) : ''} {/* [End] Review Order */} {/* [Start] Submit Button */} -
- - -
+ {products.length > 0 ? ( +
+ + +
+ ) : ''} {/* [End] Submit Button */}
-- cgit v1.2.3