-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder_confirmed.php
More file actions
148 lines (136 loc) · 5.04 KB
/
order_confirmed.php
File metadata and controls
148 lines (136 loc) · 5.04 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
<?php
session_start();
include('config.php');
// Ensure the user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
// Check if order_id is provided in the URL
if (!isset($_GET['order_id'])) {
header("Location: order_history.php");
exit();
}
$order_id = $_GET['order_id'];
// Fetch order details from the orders table (adjust column names as needed)
$sqlOrder = "SELECT * FROM orders WHERE id='$order_id' AND user_id='{$_SESSION['user_id']}'";
$resultOrder = mysqli_query($conn, $sqlOrder);
$order = mysqli_fetch_assoc($resultOrder);
if (!$order) {
header("Location: order_history.php");
exit();
}
// Fetch order items from the order_items table (joined with products for additional details)
$sqlItems = "SELECT oi.*, p.name, p.price FROM order_items oi
LEFT JOIN products p ON oi.product_id = p.id
WHERE oi.order_id='$order_id'";
$resultItems = mysqli_query($conn, $sqlItems);
$order_items = [];
while ($row = mysqli_fetch_assoc($resultItems)) {
$order_items[] = $row;
}
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Order Confirmed - Honey E-Commerce</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f8f9fa;
}
.order-header {
margin-top: 20px;
margin-bottom: 20px;
}
.table th, .table td {
vertical-align: middle;
}
</style>
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="index.php">Honey E-Commerce</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarNav" aria-controls="navbarNav"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="order_history.php">Order History</a>
</li>
<li class="nav-item">
<a class="nav-link" href="products.php">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout (<?php echo htmlspecialchars($_SESSION['name']); ?>)</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Main Container -->
<div class="container order-header">
<div class="alert alert-success text-center">
<h2>Thank You for Your Order!</h2>
<p>Your order has been confirmed successfully.</p>
</div>
</div>
<div class="container">
<!-- Order Summary Card -->
<div class="card mb-4">
<div class="card-body">
<h4>Order Details</h4>
<p><strong>Order Date:</strong> <?php echo htmlspecialchars($order['order_date']); ?></p>
<p><strong>Shipping Address:</strong><br>
<?php echo nl2br(htmlspecialchars($order['shipping_address'])); ?></p>
<p><strong>Total Amount:</strong> $<?php echo number_format($order['total_amount'], 2); ?></p>
<p><strong>Status:</strong> <?php echo htmlspecialchars($order['status'] ?? 'Pending'); ?></p>
</div>
</div>
<!-- Order Items Table -->
<h4>Items in Your Order</h4>
<table class="table table-striped">
<thead class="table-light">
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<?php
$calculatedTotal = 0;
foreach($order_items as $item):
$subtotal = $item['price'] * $item['quantity'];
$calculatedTotal += $subtotal;
?>
<tr>
<td><?php echo htmlspecialchars($item['name']); ?></td>
<td>$<?php echo number_format($item['price'], 2); ?></td>
<td><?php echo htmlspecialchars($item['quantity']); ?></td>
<td>$<?php echo number_format($subtotal, 2); ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="3" class="text-end"><strong>Total:</strong></td>
<td><strong>$<?php echo number_format($calculatedTotal, 2); ?></strong></td>
</tr>
</tbody>
</table>
<div class="text-center">
<a href="products.php" class="btn btn-warning">Continue Shopping</a>
</div>
</div>
<!-- Bootstrap JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>