order update
This commit is contained in:
@@ -102,14 +102,18 @@ const CartPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const subtotal = cartItems.reduce(
|
const subtotal =
|
||||||
(sum, item) =>
|
cartItems?.reduce((sum, item) => {
|
||||||
sum +
|
if (item.product.prices.length === 0) return sum; // narx yo'q bo'lsa qo'shmaymiz
|
||||||
Math.max(...item.product.prices.map((e) => Number(e.price))) *
|
|
||||||
Number(item.quantity),
|
// Eng yuqori narxni olish
|
||||||
0,
|
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) => {
|
const handleQuantityChange = (itemId: string, value: number) => {
|
||||||
setQuantities((prev) => ({
|
setQuantities((prev) => ({
|
||||||
...prev,
|
...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">
|
<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">
|
<span className="text-blue-600 font-bold text-xl">
|
||||||
{formatPrice(
|
{formatPrice(
|
||||||
Math.max(
|
item.product.prices.length !== 0
|
||||||
...item.product.prices.map((e) => Number(e.price)),
|
? Math.max(
|
||||||
|
...item.product.prices.map((e) =>
|
||||||
|
Number(e.price),
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
: 0,
|
||||||
true,
|
true,
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -134,14 +134,18 @@ const OrderPage = () => {
|
|||||||
const [deliveryDate, setDeliveryDate] = useState<Date>();
|
const [deliveryDate, setDeliveryDate] = useState<Date>();
|
||||||
const [selectedTimeSlot, setSelectedTimeSlot] = useState<string>('');
|
const [selectedTimeSlot, setSelectedTimeSlot] = useState<string>('');
|
||||||
|
|
||||||
const subtotal = cartItems?.reduce(
|
const subtotal =
|
||||||
(sum, item) =>
|
cartItems?.reduce((sum, item) => {
|
||||||
sum +
|
if (item.product.prices.length === 0) return sum; // narx yo'q bo'lsa qo'shmaymiz
|
||||||
Math.max(...item.product.prices.map((e) => Number(e.price))) *
|
|
||||||
item.quantity,
|
// Eng yuqori narxni olish
|
||||||
0,
|
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({
|
const [coords, setCoords] = useState({
|
||||||
latitude: 41.311081,
|
latitude: 41.311081,
|
||||||
longitude: 69.240562,
|
longitude: 69.240562,
|
||||||
@@ -573,12 +577,26 @@ const OrderPage = () => {
|
|||||||
</h4>
|
</h4>
|
||||||
<p className="text-sm text-gray-500">
|
<p className="text-sm text-gray-500">
|
||||||
{item.quantity} x{' '}
|
{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,
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
<p className="font-semibold text-sm">
|
<p className="font-semibold text-sm">
|
||||||
{formatPrice(
|
{formatPrice(
|
||||||
Number(item.product.prices[0].price) *
|
item.product.prices.length !== 0
|
||||||
item.quantity,
|
? Math.max(
|
||||||
|
...item.product.prices.map((p) =>
|
||||||
|
Number(p.price),
|
||||||
|
),
|
||||||
|
) * item.quantity
|
||||||
|
: 0 * item.quantity,
|
||||||
true,
|
true,
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user