-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrders.php
More file actions
217 lines (196 loc) · 13 KB
/
Orders.php
File metadata and controls
217 lines (196 loc) · 13 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
// Page configuration
$pageTitle = "My Orders - Shopway";
$extraCSS = ['orders'];
$extraJS = ['orders'];
// Include header
require_once 'db.php';
require_once 'includes/header.php';
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
// Get user's orders with pagination
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = 5;
$offset = ($page - 1) * $limit;
$userId = $_SESSION['user_id'];
// Get total orders count for pagination
$totalOrders = fetchRow("SELECT COUNT(*) as count FROM orders WHERE user_id = ?", [$userId])['count'] ?? 0;
$totalPages = ceil($totalOrders / $limit);
// Get orders for current page
$orders = fetchResults("SELECT * FROM orders WHERE user_id = ? ORDER BY order_date DESC LIMIT ? OFFSET ?",
[$userId, $limit, $offset],
"iii");
// Get specific order details if an order_id is provided
$orderDetails = [];
$orderItems = [];
if (isset($_GET['order_id']) && is_numeric($_GET['order_id'])) {
$orderId = (int)$_GET['order_id'];
// Get order details
$orderDetails = fetchRow("SELECT * FROM orders WHERE id = ? AND user_id = ?", [$orderId, $userId]);
if ($orderDetails) {
// Get order items
$orderItems = fetchResults(
"SELECT oi.*, p.name, p.image FROM order_items oi
JOIN products p ON oi.product_id = p.id
WHERE oi.order_id = ?",
[$orderId]
);
}
}
?>
<!-- Orders Container -->
<div class="container orders-container" style="padding: 20px 0;">
<?php if ($orderDetails): ?>
<!-- Order Details View -->
<a href="orders.php" style="display: inline-flex; align-items: center; color: #007bff; text-decoration: none; margin-bottom: 20px;">
<i class="fas fa-arrow-left" style="margin-right: 8px;"></i> Back to All Orders
</a>
<div style="background-color: #fff; border-radius: 8px; box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1); padding: 20px; margin-bottom: 30px;">
<div style="display: flex; justify-content: space-between; align-items: center; padding-bottom: 15px; border-bottom: 1px solid #f0f0f0; margin-bottom: 20px;">
<div style="font-size: 24px; color: #333;">
Order #<?php echo $orderDetails['id']; ?>
</div>
<span style="display: inline-block; padding: 5px 10px; border-radius: 20px; font-size: 14px; font-weight: 500;
background-color: <?php echo strtolower($orderDetails['status']) === 'delivered' ? '#badc58' :
(strtolower($orderDetails['status']) === 'shipped' ? '#c7ecee' :
(strtolower($orderDetails['status']) === 'processing' ? '#a0e7e5' :
(strtolower($orderDetails['status']) === 'cancelled' ? '#ffcccc' : '#ffeaa7'))); ?>;
color: <?php echo strtolower($orderDetails['status']) === 'delivered' ? '#2d5108' :
(strtolower($orderDetails['status']) === 'shipped' ? '#3c6382' :
(strtolower($orderDetails['status']) === 'processing' ? '#0a766e' :
(strtolower($orderDetails['status']) === 'cancelled' ? '#d63031' : '#d68102'))); ?>;">
<?php echo $orderDetails['status']; ?>
</span>
</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-bottom: 30px;">
<div>
<div style="margin-bottom: 20px;">
<div style="color: #777; margin-bottom: 5px; font-size: 14px;">Order Date</div>
<div style="color: #333; font-weight: 500;"><?php echo date("F j, Y, g:i a", strtotime($orderDetails['order_date'])); ?></div>
</div>
<div style="margin-bottom: 20px;">
<div style="color: #777; margin-bottom: 5px; font-size: 14px;">Payment Method</div>
<div style="color: #333; font-weight: 500;"><?php echo htmlspecialchars($orderDetails['payment_method'] ?? 'Not specified'); ?></div>
</div>
</div>
<div>
<div style="margin-bottom: 20px;">
<div style="color: #777; margin-bottom: 5px; font-size: 14px;">Shipping Address</div>
<div style="color: #333; font-weight: 500;"><?php echo nl2br(htmlspecialchars($orderDetails['shipping_address'])); ?></div>
</div>
<div style="margin-bottom: 20px;">
<div style="color: #777; margin-bottom: 5px; font-size: 14px;">Contact Phone</div>
<div style="color: #333; font-weight: 500;"><?php echo htmlspecialchars($orderDetails['contact_phone']); ?></div>
</div>
</div>
</div>
<h3>Ordered Items</h3>
<table style="width: 100%; border-collapse: collapse; margin-bottom: 30px;">
<thead>
<tr>
<th style="background-color: #f8f9fa; padding: 12px 15px; text-align: left; color: #555; font-weight: 600;">Product</th>
<th style="background-color: #f8f9fa; padding: 12px 15px; text-align: left; color: #555; font-weight: 600;">Price</th>
<th style="background-color: #f8f9fa; padding: 12px 15px; text-align: left; color: #555; font-weight: 600;">Quantity</th>
<th style="background-color: #f8f9fa; padding: 12px 15px; text-align: left; color: #555; font-weight: 600;">Total</th>
</tr>
</thead>
<tbody>
<?php
$subtotal = 0;
foreach ($orderItems as $item):
$itemTotal = $item['price'] * $item['quantity'];
$subtotal += $itemTotal;
?>
<tr>
<td style="padding: 15px; border-bottom: 1px solid #f0f0f0;">
<div style="display: flex; align-items: center;">
<img src="<?php echo BASE_URL; ?>/assets/images/<?php echo htmlspecialchars($item['image']); ?>"
alt="<?php echo htmlspecialchars($item['name']); ?>"
style="width: 60px; height: 60px; object-fit: cover; border-radius: 5px; margin-right: 15px;">
<div><?php echo htmlspecialchars($item['name']); ?></div>
</div>
</td>
<td style="padding: 15px; border-bottom: 1px solid #f0f0f0;">₱<?php echo number_format($item['price'], 2); ?></td>
<td style="padding: 15px; border-bottom: 1px solid #f0f0f0;"><?php echo $item['quantity']; ?></td>
<td style="padding: 15px; border-bottom: 1px solid #f0f0f0;">₱<?php echo number_format($itemTotal, 2); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div style="background-color: #f8f9fa; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
<div style="display: flex; justify-content: space-between; padding: 10px 0; color: #555;">
<span>Subtotal</span>
<span>₱<?php echo number_format($subtotal, 2); ?></span>
</div>
<div style="display: flex; justify-content: space-between; padding: 10px 0; color: #555;">
<span>Shipping Fee</span>
<span>₱<?php echo number_format($orderDetails['total_amount'] - $subtotal, 2); ?></span>
</div>
<div style="display: flex; justify-content: space-between; padding: 10px 0; color: #333; border-top: 2px solid #f0f0f0; margin-top: 10px; padding-top: 15px; font-weight: bold; font-size: 18px;">
<span>Total</span>
<span>₱<?php echo number_format($orderDetails['total_amount'], 2); ?></span>
</div>
</div>
</div>
<?php else: ?>
<!-- Orders List View -->
<h1 style="font-size: 2rem; margin-bottom: 30px; color: #333; border-bottom: 2px solid #f0f0f0; padding-bottom: 10px;">My Orders</h1>
<?php if (empty($orders)): ?>
<div style="text-align: center; padding: 50px 20px; background-color: #f9f9f9; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);">
<i class="fas fa-shopping-bag fa-4x" style="color: #ccc; margin-bottom: 20px;"></i>
<h2 style="font-size: 24px; margin-bottom: 15px; color: #555;">No orders yet</h2>
<p style="color: #777; margin-bottom: 25px;">You haven't placed any orders with us. Start shopping to see your orders here.</p>
<a href="<?php echo BASE_URL; ?>/products.php" style="display: inline-block; background-color: #007bff; color: white; padding: 8px 15px; border-radius: 5px; text-decoration: none;">Start Shopping</a>
</div>
<?php else: ?>
<div style="display: grid; gap: 20px;">
<?php foreach ($orders as $order): ?>
<div style="background-color: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08); padding: 20px; transition: transform 0.3s ease;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; border-bottom: 1px solid #f0f0f0; padding-bottom: 15px;">
<div style="font-size: 18px; font-weight: 600; color: #333;">Order #<?php echo $order['id']; ?></div>
<div style="color: #777; font-size: 14px;"><?php echo date("F j, Y", strtotime($order['order_date'])); ?></div>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 20px;">
<div style="font-size: 20px; font-weight: 600; color: #2ecc71;">₱<?php echo number_format($order['total_amount'], 2); ?></div>
<span style="display: inline-block; padding: 5px 10px; border-radius: 20px; font-size: 14px; font-weight: 500;
background-color: <?php echo strtolower($order['status']) === 'delivered' ? '#badc58' :
(strtolower($order['status']) === 'shipped' ? '#c7ecee' :
(strtolower($order['status']) === 'processing' ? '#a0e7e5' :
(strtolower($order['status']) === 'cancelled' ? '#ffcccc' : '#ffeaa7'))); ?>;
color: <?php echo strtolower($order['status']) === 'delivered' ? '#2d5108' :
(strtolower($order['status']) === 'shipped' ? '#3c6382' :
(strtolower($order['status']) === 'processing' ? '#0a766e' :
(strtolower($order['status']) === 'cancelled' ? '#d63031' : '#d68102'))); ?>;">
<?php echo $order['status']; ?>
</span>
</div>
<a href="orders.php?order_id=<?php echo $order['id']; ?>" style="display: inline-block; background-color: #007bff; color: white; padding: 8px 15px; border-radius: 5px; text-decoration: none; transition: background-color 0.3s ease;">View Details</a>
</div>
<?php endforeach; ?>
</div>
<?php if ($totalPages > 1): ?>
<div style="display: flex; justify-content: center; margin-top: 30px;">
<?php if ($page > 1): ?>
<a href="orders.php?page=<?php echo $page - 1; ?>" style="display: inline-block; padding: 8px 16px; margin: 0 5px; border: 1px solid #ddd; color: #333; border-radius: 4px; text-decoration: none;">« Previous</a>
<?php endif; ?>
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<a href="orders.php?page=<?php echo $i; ?>"
style="display: inline-block; padding: 8px 16px; margin: 0 5px; border: 1px solid <?php echo $i == $page ? '#007bff' : '#ddd'; ?>; color: <?php echo $i == $page ? 'white' : '#333'; ?>; background-color: <?php echo $i == $page ? '#007bff' : 'transparent'; ?>; border-radius: 4px; text-decoration: none;">
<?php echo $i; ?>
</a>
<?php endfor; ?>
<?php if ($page < $totalPages): ?>
<a href="orders.php?page=<?php echo $page + 1; ?>" style="display: inline-block; padding: 8px 16px; margin: 0 5px; border: 1px solid #ddd; color: #333; border-radius: 4px; text-decoration: none;">Next »</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<?php
// Include footer
require_once 'includes/footer.php';
?>