-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders.php
More file actions
85 lines (78 loc) · 4.12 KB
/
Copy pathorders.php
File metadata and controls
85 lines (78 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
$pageTitle = 'My Orders';
require_once 'includes/auth.php';
require_once 'classes/Order.php';
require_once 'config/database.php';
$orderModel = new Order();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'cancel_order') {
if (validateCsrfToken()) {
$orderModel->cancelOrder((int)$_POST['order_id'], (int)$_SESSION['user_id']);
}
header('Location: orders.php');
exit;
}
$orders = $orderModel->getByUserId($_SESSION['user_id']);
require_once 'includes/header.php';
?>
<div class="orders-page">
<h1><i class="fas fa-box"></i> My Orders</h1>
<?php if (empty($orders)): ?>
<div class="cart-empty">
<i class="fas fa-box-open"></i>
<h2>No orders yet</h2>
<p>Start shopping and your orders will appear here.</p>
<a href="index.php" class="hero-cta"><i class="fas fa-shopping-bag"></i> Start Shopping</a>
</div>
<?php else: ?>
<?php foreach ($orders as $order):
$details = $orderModel->getOrderDetails($order['id'], $_SESSION['user_id']);
?>
<div class="order-card">
<div class="order-header">
<div>
<span class="order-id">Order #<?= $order['id'] ?></span>
<span style="color:var(--text-light);margin-left:12px;font-size:.85rem">
<?= date('M d, Y', strtotime($order['created_at'])) ?>
</span>
</div>
<div style="display:flex;align-items:center;gap:12px">
<span class="badge <?= Order::getStatusBadge($order['status']) ?>"><?= ucfirst($order['status']) ?></span>
<span style="font-weight:700"><?= CURRENCY . number_format($order['total_amount'], 2) ?></span>
<?php if ($order['status'] === 'pending'): ?>
<form method="POST" style="display:inline" onsubmit="return confirm('Cancel this order?');">
<input type="hidden" name="action" value="cancel_order">
<input type="hidden" name="order_id" value="<?= $order['id'] ?>">
<?= csrfField() ?>
<button type="submit" class="btn-text-small text-danger" style="border:none;background:none;cursor:pointer">
<i class="fas fa-times-circle"></i> Cancel
</button>
</form>
<?php endif; ?>
<i class="fas fa-chevron-down"></i>
</div>
</div>
<div class="order-body">
<?php if ($details && !empty($details['items'])): ?>
<?php foreach ($details['items'] as $item): ?>
<div class="order-item">
<img src="<?= htmlspecialchars($item['image'] ?: 'assets/images/placeholder.png') ?>" alt="<?= htmlspecialchars($item['name']) ?>">
<div style="flex:1">
<div style="font-weight:600"><?= htmlspecialchars($item['name']) ?></div>
<div style="color:var(--text-light);font-size:.85rem">Qty: <?= $item['quantity'] ?> × <?= CURRENCY . number_format($item['unit_price'], 2) ?></div>
</div>
<div style="font-weight:600"><?= CURRENCY . number_format($item['unit_price'] * $item['quantity'], 2) ?></div>
</div>
<?php endforeach; ?>
<div class="order-total" style="display:flex;justify-content:space-between;align-items:center;margin-top:16px;">
<a href="invoice.php?order_id=<?= $order['id'] ?>" class="btn-text-small" target="_blank" style="font-size:0.88rem;">
<i class="fas fa-file-invoice"></i> View/Print Invoice
</a>
<span>Total: <?= CURRENCY . number_format($order['total_amount'], 2) ?></span>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php require_once 'includes/footer.php'; ?>