36766-vm/order_details.php
Flatlogic Bot 6c14b2436f 2.0
2025-12-18 09:40:37 +00:00

79 lines
2.0 KiB
PHP

<?php
require_once 'includes/header.php';
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
if (!isset($_GET['id'])) {
header('Location: orders.php');
exit;
}
$order_id = $_GET['id'];
$pdo = db();
// Fetch order details
$sql = "SELECT * FROM orders WHERE id = ? AND user_id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$order_id, $_SESSION['user_id']]);
$order = $stmt->fetch();
if (!$order) {
header('Location: orders.php');
exit;
}
// Fetch order items
$sql = "
SELECT oi.*, p.name as product_name
FROM order_items oi
JOIN products p ON oi.product_id = p.id
WHERE oi.order_id = ?
";
$stmt = $pdo->prepare($sql);
$stmt->execute([$order_id]);
$order_items = $stmt->fetchAll();
?>
<h1 class="mb-4">Order Details #<?php echo $order['id']; ?></h1>
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Order Summary</h5>
<p><strong>Total Amount:</strong> $<?php echo number_format($order['total_amount'], 2); ?></p>
<p><strong>Status:</strong> <?php echo htmlspecialchars($order['status']); ?></p>
<p><strong>Date:</strong> <?php echo $order['created_at']; ?></p>
</div>
</div>
<h2 class="mb-4">Items in this Order</h2>
<table class="table">
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($order_items as $item): ?>
<tr>
<td><?php echo htmlspecialchars($item['product_name']); ?></td>
<td><?php echo $item['quantity']; ?></td>
<td>$<?php echo number_format($item['price'], 2); ?></td>
<td>$<?php echo number_format($item['price'] * $item['quantity'], 2); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="orders.php" class="btn btn-secondary">Back to Orders</a>
<?php require_once 'includes/footer.php'; ?>