From 55c8f1c3c6c3566afe6555b7e3714f2738d0bb8e Mon Sep 17 00:00:00 2001 From: Mqdd Date: Fri, 13 Mar 2026 09:56:07 +0700 Subject: fix selected variant --- .../product-detail/components/AddToCart.tsx | 5 ++-- .../product-detail/components/AddToQuotation.tsx | 7 +++--- .../product-detail/components/PriceAction.tsx | 27 +++++++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 18f90012..a8523f55 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -51,7 +51,7 @@ const AddToCart = ({ const { isMobile, isDesktop } = useDevice(); - const { askAdminUrl } = useProductDetail(); + const { askAdminUrl, selectedVariant } = useProductDetail(); const [product, setProducts] = useState(products); const [status, setStatus] = useState('idle'); @@ -72,8 +72,7 @@ const AddToCart = ({ weight: '', isFlashSale: false, }); - const hasPrice = - !!product?.lowest_price && Number(product.lowest_price.price) > 0; + const hasPrice = Number(selectedVariant?.price?.price_discount || 0) > 0; useEffect(() => { const fetchData = async () => { diff --git a/src-migrate/modules/product-detail/components/AddToQuotation.tsx b/src-migrate/modules/product-detail/components/AddToQuotation.tsx index e26e271f..747e8718 100644 --- a/src-migrate/modules/product-detail/components/AddToQuotation.tsx +++ b/src-migrate/modules/product-detail/components/AddToQuotation.tsx @@ -44,7 +44,7 @@ const AddToQuotation = ({ isClosable: true, }); - const { askAdminUrl } = useProductDetail(); + const { askAdminUrl, selectedVariant } = useProductDetail(); const { isMobile, isDesktop } = useDevice(); const [product, setProducts] = useState(products); @@ -64,8 +64,8 @@ const AddToQuotation = ({ `fq=-manufacture_id_i:${product.manufacture?.id || 0}`, ].join('&'); const [addCartAlert, setAddCartAlert] = useState(false); - const hasPrice = - !!product?.lowest_price && Number(product.lowest_price.price) > 0; + + const hasPrice = Number(selectedVariant?.price?.price_discount || 0) > 0; const handleButton = async () => { if (typeof auth !== 'object') { @@ -138,6 +138,7 @@ const AddToQuotation = ({ className="w-full border border-gray-300 p-2 gap-2 flex items-center justify-center text-gray-600 hover:text-red-600 hover:border-red-600 transition-all font-normal text-sm" _hover={{ textDecoration: 'none' }} onClick={handleButton} + isDisabled={!hasPrice} > Penawaran diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx index ea65b3d1..37ee5055 100644 --- a/src-migrate/modules/product-detail/components/PriceAction.tsx +++ b/src-migrate/modules/product-detail/components/PriceAction.tsx @@ -80,7 +80,8 @@ const PriceAction = ({ product, onCompare }: Props) => { const validJsonString = stringVoucher.replace(/'/g, '"'); voucherPastiHemat = JSON.parse(validJsonString); } - const hasPrice = Number(product?.lowest_price?.price) > 0; + const hasPrice = Number(selectedVariant?.price?.price_discount || 0) > 0; + const price = selectedVariant?.price; return (
{ }`} id='price-section' > - {!!activePrice && activePrice.price > 0 && ( + {!!price && price.price > 0 && ( <>
- {activePrice.discount_percentage > 0 && ( + {price.discount_percentage > 0 && ( <>
- {Math.floor(activePrice.discount_percentage)}% + {Math.floor(price.discount_percentage)}%
- Rp {formatCurrency(activePrice.price || 0)} + Rp {formatCurrency(price.price || 0)}
)}
- Rp {formatCurrency(activePrice.price_discount || 0)} + Rp {formatCurrency(price.price_discount || 0)}
Termasuk PPN: Rp{' '} - {formatCurrency(Math.round(activePrice.price_discount * PPN))} + {formatCurrency(Math.round(price.price_discount * PPN))}
- {activePrice.discount_percentage > 0 ? ( + {price.discount_percentage > 0 ? ( <>
- {Math.floor(activePrice.discount_percentage)}% + {Math.floor(price.discount_percentage)}%
{/* harga setelah diskon (main-price) di kiri */}
- Rp {formatCurrency(activePrice.price_discount || 0)} + Rp {formatCurrency(price.price_discount || 0)}
{/* harga coret di kanan */}
- Rp {formatCurrency(activePrice.price || 0)} + Rp {formatCurrency(price.price || 0)}
) : ( // kalau tidak ada diskon, tampilkan harga normal saja
- Rp {formatCurrency(activePrice.price || 0)} + Rp {formatCurrency(price.price || 0)}
)}
Termasuk PPN: Rp{' '} - {formatCurrency(Math.round(activePrice.price_discount * PPN))} + {formatCurrency(Math.round(price.price_discount * PPN))}
-- cgit v1.2.3