From b7846c7bc91855b1edb1a3eb42d88bfd7875a9e1 Mon Sep 17 00:00:00 2001 From: Samandar Turgunboyev Date: Wed, 28 Jan 2026 16:19:52 +0500 Subject: [PATCH] order update --- src/features/cart/ui/CartPage.tsx | 28 ++++++++++++++-------- src/features/cart/ui/OrderPage.tsx | 38 ++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/features/cart/ui/CartPage.tsx b/src/features/cart/ui/CartPage.tsx index 58ebef7..3103411 100644 --- a/src/features/cart/ui/CartPage.tsx +++ b/src/features/cart/ui/CartPage.tsx @@ -102,13 +102,17 @@ const CartPage = () => { ); - const subtotal = cartItems.reduce( - (sum, item) => - sum + - Math.max(...item.product.prices.map((e) => Number(e.price))) * - Number(item.quantity), - 0, - ); + const subtotal = + cartItems?.reduce((sum, item) => { + if (item.product.prices.length === 0) return sum; // narx yo'q bo'lsa qo'shmaymiz + + // Eng yuqori narxni olish + const maxPrice = Math.max( + ...item.product.prices.map((p) => Number(p.price)), + ); + + return sum + maxPrice * item.quantity; + }, 0) || 0; // cartItems bo'sh bo'lsa 0 qaytaradi const handleQuantityChange = (itemId: string, value: number) => { setQuantities((prev) => ({ @@ -180,9 +184,13 @@ const CartPage = () => {
{formatPrice( - Math.max( - ...item.product.prices.map((e) => Number(e.price)), - ), + item.product.prices.length !== 0 + ? Math.max( + ...item.product.prices.map((e) => + Number(e.price), + ), + ) + : 0, true, )} diff --git a/src/features/cart/ui/OrderPage.tsx b/src/features/cart/ui/OrderPage.tsx index 5827368..1812937 100644 --- a/src/features/cart/ui/OrderPage.tsx +++ b/src/features/cart/ui/OrderPage.tsx @@ -134,13 +134,17 @@ const OrderPage = () => { const [deliveryDate, setDeliveryDate] = useState(); const [selectedTimeSlot, setSelectedTimeSlot] = useState(''); - const subtotal = cartItems?.reduce( - (sum, item) => - sum + - Math.max(...item.product.prices.map((e) => Number(e.price))) * - item.quantity, - 0, - ); + const subtotal = + cartItems?.reduce((sum, item) => { + if (item.product.prices.length === 0) return sum; // narx yo'q bo'lsa qo'shmaymiz + + // Eng yuqori narxni olish + const maxPrice = Math.max( + ...item.product.prices.map((p) => Number(p.price)), + ); + + return sum + maxPrice * item.quantity; + }, 0) || 0; // cartItems bo'sh bo'lsa 0 qaytaradi const [coords, setCoords] = useState({ latitude: 41.311081, @@ -573,12 +577,26 @@ const OrderPage = () => {

{item.quantity} x{' '} - {formatPrice(item.product.prices[0].price, true)} + {formatPrice( + item.product.prices.length !== 0 + ? Math.max( + ...item.product.prices.map((p) => + Number(p.price), + ), + ) + : 0, + true, + )}

{formatPrice( - Number(item.product.prices[0].price) * - item.quantity, + item.product.prices.length !== 0 + ? Math.max( + ...item.product.prices.map((p) => + Number(p.price), + ), + ) * item.quantity + : 0 * item.quantity, true, )}