fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]); if (!$order) { setFlash('error', 'Order not found'); header('Location: /admin/orders.php'); exit; } // Handle status update if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; if ($action === 'update_status') { $status = $_POST['status'] ?? ''; $trackingNumber = $_POST['tracking_number'] ?? ''; $updateData = ['order_status' => $status]; if ($trackingNumber) { $updateData['tracking_number'] = $trackingNumber; } db()->update('orders', $updateData, 'order_id = :id', ['id' => $orderId]); setFlash('success', 'Order status updated'); header('Location: /admin/order.php?id=' . $orderId); exit; } if ($action === 'add_note') { $note = trim($_POST['note'] ?? ''); if ($note) { $existingNotes = $order['notes'] ?? ''; $newNote = '[' . date('M j, Y g:i A') . '] ' . $note; $allNotes = $existingNotes ? $existingNotes . "\n" . $newNote : $newNote; db()->update('orders', ['notes' => $allNotes], 'order_id = :id', ['id' => $orderId]); setFlash('success', 'Note added'); header('Location: /admin/order.php?id=' . $orderId); exit; } } } $items = json_decode($order['items'], true) ?? []; $shippingAddress = json_decode($order['shipping_address'], true) ?? []; $statuses = ['pending', 'confirmed', 'processing', 'shipped', 'delivered', 'cancelled', 'refunded']; ?>
| Product | Price | Qty | Total |
|---|---|---|---|
| = htmlspecialchars($item['name']) ?> = htmlspecialchars($item['name']) ?> | = formatCurrency($item['price']) ?> | = $item['quantity'] ?> | = formatCurrency($item['total']) ?> |
| Subtotal | = formatCurrency($order['subtotal']) ?> | ||
| Shipping | = formatCurrency($order['shipping_cost']) ?> | ||
| Tax | = formatCurrency($order['tax']) ?> | ||
| Discount | -= formatCurrency($order['discount']) ?> | ||
| Total | = formatCurrency($order['total']) ?> | ||
= htmlspecialchars($order['notes']) ?>
No notes yet.
= htmlspecialchars($order['customer_name']) ?>
= htmlspecialchars($order['customer_email']) ?>
= htmlspecialchars($order['customer_phone']) ?>
View Customer
= htmlspecialchars($shippingAddress['address'] ?? '') ?>
= htmlspecialchars($shippingAddress['city'] ?? '') ?>,
= htmlspecialchars($shippingAddress['state'] ?? '') ?>
= htmlspecialchars($shippingAddress['zip'] ?? '') ?>