Spaces:
Sleeping
Sleeping
Kush-Singh-26
synced backend and frontend, added more menu items, ui and admin page improvements
56fb0d1 Download api/get_user_orders.php from Kush26/kiit-kaffe: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/Kush26/kiit-kaffe/resolve/main/api/get_user_orders.php
- Command line
-
hf download hf://spaces/Kush26/kiit-kaffe/api/get_user_orders.php
-
curl -L -o get_user_orders.php https://huggingface.co/spaces/Kush26/kiit-kaffe/resolve/main/api/get_user_orders.php
1.17 kB
| header("Content-Type: application/json"); | |
| include "db.php"; | |
| $data = json_decode(file_get_contents("php://input"), true); | |
| if (!isset($data["user_id"])) { | |
| echo json_encode(["status" => "error", "message" => "Missing user_id"]); | |
| exit; | |
| } | |
| $user_id = $data["user_id"]; | |
| try { | |
| // Fetch orders with items | |
| $stmt = $conn->prepare(" | |
| SELECT o.id, o.order_code, o.total, o.status, o.payment_method, o.created_at, | |
| GROUP_CONCAT(oi.item_name SEPARATOR ', ') as items, | |
| SUM(oi.quantity) as total_items | |
| FROM orders o | |
| LEFT JOIN order_items oi ON o.id = oi.order_id | |
| WHERE o.user_id = ? | |
| GROUP BY o.id, o.order_code, o.total, o.status, o.payment_method, o.created_at | |
| ORDER BY o.created_at DESC | |
| "); | |
| $stmt->execute([$user_id]); | |
| $orders = $stmt->fetchAll(PDO::FETCH_ASSOC); | |
| echo json_encode([ | |
| "status" => "success", | |
| "orders" => $orders | |
| ]); | |
| } catch (Exception $e) { | |
| error_log("Order fetch error: " . $e->getMessage()); | |
| echo json_encode([ | |
| "status" => "error", | |
| "message" => "Failed to fetch orders: " . $e->getMessage() | |
| ]); | |
| } | |