diff --git a/src/features/cart/ui/CartPage.tsx b/src/features/cart/ui/CartPage.tsx index 7e2297c..2bb4d3d 100644 --- a/src/features/cart/ui/CartPage.tsx +++ b/src/features/cart/ui/CartPage.tsx @@ -146,6 +146,12 @@ const CartPage = () => { }); }; + const price = cartItems?.map((item) => + item.product.prices.find((p) => p.price_type.code === '1') + ? item.product.prices.find((p) => p.price_type.code === '1')?.price + : Math.min(...item.product.prices.map((p) => Number(p.price))), + ); + if (isLoading) return (
@@ -177,10 +183,15 @@ const CartPage = () => { const subtotal = cartItems.reduce((sum, item) => { if (!item.product.prices.length) return sum; - const price = Math.min( - ...item.product.prices.map((p) => Number(p.price)), - ); + + const price = item.product.prices.find((p) => p.price_type.code === '1') + ? Number( + item.product.prices.find((p) => p.price_type.code === '1')?.price, + ) + : Math.min(...item.product.prices.map((p) => Number(p.price))); + const qty = quantities[item.id] ?? item.quantity; + return sum + price * qty; }, 0) || 0; @@ -243,12 +254,7 @@ const CartPage = () => {
- {formatPrice( - Math.min( - ...item.product.prices.map((p) => Number(p.price)), - ), - true, - )} + {formatPrice(Number(price), true)} /{measurementDisplay} diff --git a/src/features/cart/ui/OrderPage.tsx b/src/features/cart/ui/OrderPage.tsx index 8ff996f..6688e1b 100644 --- a/src/features/cart/ui/OrderPage.tsx +++ b/src/features/cart/ui/OrderPage.tsx @@ -139,11 +139,13 @@ const OrderPage = () => { if (item.product.prices.length === 0) return sum; // narx yo'q bo'lsa qo'shmaymiz // Eng yuqori narxni olish - const maxPrice = Math.min( - ...item.product.prices.map((p) => Number(p.price)), - ); + const maxPrice = item.product.prices.find( + (p) => p.price_type.code === '1', + ) + ? item.product.prices.find((p) => p.price_type.code === '1')?.price + : Math.min(...item.product.prices.map((p) => Number(p.price))); - return sum + maxPrice * item.quantity; + return sum + Number(maxPrice) * item.quantity; }, 0) || 0; // cartItems bo'sh bo'lsa 0 qaytaradi const [coords, setCoords] = useState({ diff --git a/src/features/product/ui/Product.tsx b/src/features/product/ui/Product.tsx index 13555e7..057b8dc 100644 --- a/src/features/product/ui/Product.tsx +++ b/src/features/product/ui/Product.tsx @@ -213,7 +213,9 @@ const ProductDetail = () => { }; const subtotal = data?.prices?.length - ? Math.min(...data.prices.map((p) => Number(p.price))) + ? data.prices.find((p) => p.price_type.code === '1') + ? data.prices.find((p) => p.price_type.code === '1')?.price + : Math.min(...data.prices.map((p) => Number(p.price))) : 0; /* ---------------- LOADING ---------------- */ @@ -250,7 +252,7 @@ const ProductDetail = () => {
- {formatPrice(subtotal, true)} + {formatPrice(Number(subtotal), true)} /{measurementDisplay}
@@ -298,7 +300,7 @@ const ProductDetail = () => {
- {t('Jami')}: {formatPrice(subtotal * numericQty, true)} + {t('Jami')}: {formatPrice(Number(subtotal) * numericQty, true)}
diff --git a/src/shared/config/api/product/type.ts b/src/shared/config/api/product/type.ts index c3899f9..358e271 100644 --- a/src/shared/config/api/product/type.ts +++ b/src/shared/config/api/product/type.ts @@ -40,6 +40,7 @@ export interface ProductListResult { price_type: { id: number; name: string; + code: string; }; }[]; balance: number; @@ -76,6 +77,7 @@ export interface ProductDetail { price_type: { id: number; name: string; + code: string; }; }[]; } @@ -131,6 +133,7 @@ export interface FavouriteProductRes { price_type: { id: number; name: string; + code: string; }; }[]; } diff --git a/src/widgets/categories/ui/product-card.tsx b/src/widgets/categories/ui/product-card.tsx index d1a0288..c0c8341 100644 --- a/src/widgets/categories/ui/product-card.tsx +++ b/src/widgets/categories/ui/product-card.tsx @@ -184,6 +184,10 @@ export function ProductCard({ }, }); + const price = product.prices.find((p) => p.price_type.code === '1') + ? product.prices.find((p) => p.price_type.code === '1')?.price + : Math.min(...product.prices.map((p) => Number(p.price))); + /** ❌ Error */ if (error) { return ( @@ -242,10 +246,7 @@ export function ProductCard({
{product.prices.length > 0 && (

- {formatPrice( - Math.min(...product.prices.map((p) => Number(p.price))), - true, - )} + {formatPrice(Number(price), true)} /{measurementDisplay} diff --git a/src/widgets/navbar/ui/SearchResult.tsx b/src/widgets/navbar/ui/SearchResult.tsx index bec9f2a..658cc9e 100644 --- a/src/widgets/navbar/ui/SearchResult.tsx +++ b/src/widgets/navbar/ui/SearchResult.tsx @@ -107,7 +107,9 @@ export const SearchResult = ({ query }: SearchResultProps) => { ? product.images[0].image : BASE_URL + product.images[0].image : LogosProduct; - const price = product.prices?.[0]?.price; + const price = product.prices.find((p) => p.price_type.code === '1') + ? product.prices.find((p) => p.price_type.code === '1')?.price + : Math.min(...product.prices.map((p) => Number(p.price))); return (

{

{product.name}

- {price && ( -

- {formatPrice( - Math.min(...product.prices.map((p) => Number(p.price))), - true, - )} -

- )} +

+ {formatPrice(Number(price), true)} +

);