From b39b1b05ab6fc32ea3fdf5b3793511ef17d682fb Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 1 Nov 2025 09:51:34 +0700 Subject: show price after discount --- src/lib/product/components/ProductCard.jsx | 240 ++++++++++++++++++----------- 1 file changed, 146 insertions(+), 94 deletions(-) diff --git a/src/lib/product/components/ProductCard.jsx b/src/lib/product/components/ProductCard.jsx index b6a3cfad..2715c6e8 100644 --- a/src/lib/product/components/ProductCard.jsx +++ b/src/lib/product/components/ProductCard.jsx @@ -220,11 +220,13 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { {product?.name} + {/* ---------- HARGA ---------- */} {product?.flashSale?.id > 0 && product?.lowestPrice.discountPercentage > 0 ? ( + // ===== CASE FLASH SALE =====
- + {product?.lowestPrice.priceDiscount > 0 ? ( currencyFormat(product?.lowestPrice.priceDiscount) ) : ( @@ -238,62 +240,86 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { )} + {currencyFormat(product.lowestPrice.price)}
) : ( -
- {product?.lowestPrice.price > 0 ? ( - <> - {currencyFormat(product?.lowestPrice.priceDiscount)} -
- Include PPN:{' '} - {currencyFormat( - product.lowestPrice.price * - process.env.NEXT_PUBLIC_PPN - )} + // ===== BUKAN FLASH SALE ===== + (() => { + const basePrice = product?.lowestPrice?.priceDiscount || 0; + const voucherCut = discount || 0; + const finalAfterVoucher = Math.max(basePrice - voucherCut, 0); + + // CASE 1: ada harga (>0) + if (product?.lowestPrice?.price > 0) { + if (voucherCut > 0) { + return ( +
+ {/* baris harga sekarang + harga coret */} +
+ {/* harga setelah voucher */} + + + {currencyFormat(finalAfterVoucher)} + + + {/* harga sebelum voucher, dicoret, truncate kalau kepanjangan */} + + {currencyFormat(basePrice)} + +
+ + {/* PPN pakai harga finalAfterVoucher */} +
+ Include PPN:{' '} + {currencyFormat( + finalAfterVoucher * process.env.NEXT_PUBLIC_PPN + )} +
+
+ ); + } + + // CASE 1b: ga ada voucher + return ( +
+ {currencyFormat(basePrice)} +
+ Include PPN:{' '} + {currencyFormat( + product.lowestPrice.price * + process.env.NEXT_PUBLIC_PPN + )} +
- - ) : ( - - Call for Inquiry - - )} -
- )} - - {discount > 0 && (product?.flashSale?.id ?? 0) < 1 && ( -
-
- {/* label jangan pecah */} - - Voucher - - - {/* chip bisa mengecil & memotong teks di dalam */} - - - {/* nominal: truncate */} - - {currencyFormat(discount)} - - -
-
+ ); + } + + // CASE 2: harga 0 → call for inquiry + return ( +
+ + Call for Inquiry + +
+ ); + })() )} + {/* ---------- /HARGA ---------- */}
{(product?.stockTotal > 0 || product?.qtySold > 0) && ( @@ -438,11 +464,13 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { {product?.name} + {/* ---------- HARGA ---------- */} {product?.flashSale?.id > 0 && product?.lowestPrice.discountPercentage > 0 ? ( + // ===== CASE FLASH SALE =====
- + {product?.lowestPrice.priceDiscount > 0 ? ( currencyFormat(product?.lowestPrice.priceDiscount) ) : ( @@ -456,62 +484,86 @@ const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => { )} + {currencyFormat(product.lowestPrice.price)}
) : ( -
- {product?.lowestPrice.price > 0 ? ( - <> - {currencyFormat(product?.lowestPrice.priceDiscount)} -
- Include PPN:{' '} - {currencyFormat( - product.lowestPrice.price * - process.env.NEXT_PUBLIC_PPN - )} + // ===== BUKAN FLASH SALE ===== + (() => { + const basePrice = product?.lowestPrice?.priceDiscount || 0; + const voucherCut = discount || 0; + const finalAfterVoucher = Math.max(basePrice - voucherCut, 0); + + // CASE 1: ada harga (>0) + if (product?.lowestPrice?.price > 0) { + if (voucherCut > 0) { + return ( +
+ {/* baris harga sekarang + harga coret */} +
+ {/* harga setelah voucher */} + + + {currencyFormat(finalAfterVoucher)} + + + {/* harga sebelum voucher, dicoret, truncate kalau kepanjangan */} + + {currencyFormat(basePrice)} + +
+ + {/* PPN pakai harga finalAfterVoucher */} +
+ Include PPN:{' '} + {currencyFormat( + finalAfterVoucher * process.env.NEXT_PUBLIC_PPN + )} +
+
+ ); + } + + // CASE 1b: ga ada voucher + return ( +
+ {currencyFormat(basePrice)} +
+ Include PPN:{' '} + {currencyFormat( + product.lowestPrice.price * + process.env.NEXT_PUBLIC_PPN + )} +
- - ) : ( - - Call for Inquiry - - )} -
- )} - - {discount > 0 && (product?.flashSale?.id ?? 0) < 1 && ( -
-
- {/* label jangan pecah */} - - Voucher - - - {/* chip bisa mengecil & memotong teks di dalam */} - - - {/* nominal: truncate */} - - {currencyFormat(discount)} - - -
-
+ ); + } + + // CASE 2: harga 0 → call for inquiry + return ( + + ); + })() )} + {/* ---------- /HARGA ---------- */} {(product?.stockTotal > 0 || product?.qtySold > 0) && (
-- cgit v1.2.3