From 69e3e2e0abe1e3973ac928289367e17d39d37ed9 Mon Sep 17 00:00:00 2001 From: Jelaletdin12 Date: Fri, 13 Mar 2026 15:39:24 +0500 Subject: [PATCH] fixed order and cart req --- app/[locale]/cart/page.tsx | 3 +++ features/cart/hooks/useCart.ts | 32 +++++++++++++++++++++++--------- next.config.ts | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/[locale]/cart/page.tsx b/app/[locale]/cart/page.tsx index 4a3e8d3..a77a475 100644 --- a/app/[locale]/cart/page.tsx +++ b/app/[locale]/cart/page.tsx @@ -128,6 +128,8 @@ export default function CartPage() { ); if (!selectedProvinceData) return; + const product_ids = cartItems.map((item) => item.product.id); + createOrder( { customer_name: `${name} ${lastName}`.trim(), @@ -137,6 +139,7 @@ export default function CartPage() { payment_type_id: paymentType.id, region: selectedRegion, notes: note || undefined, + product_ids, }, { onSuccess: () => { diff --git a/features/cart/hooks/useCart.ts b/features/cart/hooks/useCart.ts index 26cb777..598790f 100644 --- a/features/cart/hooks/useCart.ts +++ b/features/cart/hooks/useCart.ts @@ -40,21 +40,34 @@ function transformCartResponse(response: any): CartResponse { (response.trim().startsWith(" { + if (Array.isArray(raw)) return raw; + + // GET response: data = { tmpost: [...], ... } — merge all channel arrays + if (typeof raw === "object" && raw !== null) { + return Object.values(raw).flat() as CartItem[]; + } + + return []; + }; + + if (typeof response === "object" && response !== null) { + return { + message: response.message || "success", + data: normalize(response.data), + }; } if (typeof response === "string") { try { - return JSON.parse(response); + const parsed = JSON.parse(response); + return { + message: parsed.message || "success", + data: normalize(parsed.data), + }; } catch { return { message: "error", data: [] }; } @@ -471,6 +484,7 @@ export function useCreateOrder() { delivery_at?: string; region: string; notes?: string; + product_ids: number[]; }) => { const response = await apiClient.post("/orders", payload); return response.data; diff --git a/next.config.ts b/next.config.ts index 73d2e7e..54c917e 100644 --- a/next.config.ts +++ b/next.config.ts @@ -12,7 +12,7 @@ const nextConfig: NextConfig = { remotePatterns: [ { protocol: "https", - hostname: "hyzmat.app", + hostname: "smartelektronika.com", // port: "8080", }, ],