order update
This commit is contained in:
@@ -102,13 +102,17 @@ const CartPage = () => {
|
||||
</div>
|
||||
);
|
||||
|
||||
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 = () => {
|
||||
<div className="flex items-center gap-2 mb-3 max-lg:flex-col max-lg:items-start max-lg:gap-1">
|
||||
<span className="text-blue-600 font-bold text-xl">
|
||||
{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,
|
||||
)}
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user