This repository was archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.php
More file actions
268 lines (257 loc) · 9.71 KB
/
checkout.php
File metadata and controls
268 lines (257 loc) · 9.71 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!doctype html>
<html class="no-js" lang="en">
<?php
include_once 'elements\head.php';
include_once 'config\conn.php';
?>
<body>
<!-- WRAPPER START -->
<div class="wrapper bg-dark-white">
<?php
include_once 'elements\header.php';
require_once 'session.php';
$id = $_SESSION['customer_id'];
$sql = "SELECT * FROM customer WHERE id = '$id' LIMIT 1";
$order = mysqli_query($conn, 'SELECT * FROM `order` WHERE customer_id = ' . $id);
$result = mysqli_query($conn, $sql);
$customer = mysqli_fetch_assoc($result);
// send order to database
if (isset($_POST['submit'])) {
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$payment_method_id = $_POST['payment_method_id'];
$shipping_method_id = $_POST['shipping_method_id'];
$customer_id = $_SESSION['customer_id'];
// subTotal, vat, total, orderTotal
$subTotal = $_POST['subTotal'];
$vat = $_POST['vat'];
$total = $_POST['total'];
$orderTotal = $_POST['orderTotal'];
$sql = "INSERT INTO `order`(`email`, `phone`, `address`, `payment_method_id`, `customer_id`, `total`, `subTotal`, `vat`, `orderTotal`, `shipping_method_id`) VALUES ('$email','$phone','$address','$payment_method_id','$customer_id', '$total', '$subTotal', '$vat', '$orderTotal', '$shipping_method_id')";
$result = mysqli_query($conn, $sql);
if ($result) {
// làm sạch giỏ hàng
unset($_SESSION['cart']);
echo '<script>alert("Order successfully!")</script>';
} else {
echo '4';
echo '<script>alert("Order failed!")</script>';
}
}
?>
<!-- HEADING-BANNER START -->
<div class="heading-banner-area overlay-bg">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="heading-banner">
<div class="heading-banner-title">
<h2>check out</h2>
</div>
<div class="breadcumbs pb-15">
<ul>
<li><a href="index.php">Home</a></li>
<li>check out</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- HEADING-BANNER END -->
<!-- CHECKOUT-AREA START -->
<div class="shopping-cart-area pt-80 pb-80">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="shopping-cart">
<!-- Nav tabs -->
<ul class="cart-page-menu nav row clearfix mb-30">
<li><a href="cart.php">shopping cart</a></li>
<li><a href="wishlist.php">wishlist</a></li>
<li><a class="active" href="checkout.php">check out</a></li>
<li><a href="order.php">order complete</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<!-- check-out start -->
<div class="tab-pane active" id="check-out">
<div class="shop-cart-table check-out-wrap">
<div class="row">
<div class="col-md-6">
<div class="billing-details pr-20">
<h4 class="title-1 title-border text-uppercase mb-30">billing
details</h4>
<input type="text" placeholder="Your name here..."
name="fullname"
value="<?php echo $customer['fullname'] ?>"=>
<input type="text" placeholder="Email address here..."
name="email" value="<?php echo $customer['email'] ?>">
<input type="text" placeholder="Phone here..." name="phone"
value="<?php echo $customer['phone'] ?>">
<input type="date" name="birthday"
placeholder="Birthday here..."
value="<?php echo $customer['birthday'] ?>">
<textarea placeholder="Your address here..."
class="custom-textarea"
name="address"><?php echo $customer['address'] ?></textarea>
</div>
</div>
<div class="col-md-6 mt-xs-30">
<div class="billing-details pl-20">
<h4 class="title-1 title-border text-uppercase mb-30">Shipping
address</h4>
<ul>
<li>
<h6>
<?php echo $customer['fullname'] ?>
</h6>
</li>
<li>
<h6>
<?php echo $customer['email'] ?>
</h6>
</li>
<li>
<h6>
<?php echo $customer['phone'] ?>
</h6>
</li>
<li>
<h6>
<?php echo $customer['birthday'] ?>
</h6>
</li>
<li>
<h6>
<?php echo $customer['address'] ?>
</h6>
</li>
</ul>
</div>
</div>
<div class="col-md-6">
<div class="our-order payment-details mt-60 pr-20">
<h4 class="title-1 title-border text-uppercase mb-30">our order
</h4>
<table>
<tbody>
<?php
// echo order details
$subTotal = $total * 0.01;
$vat = $total * 0.05;
if (isset($_SESSION['cart'])) {
foreach ($_SESSION['cart'] as $product) {
echo '<tr>
<td class="text-left">' . $product['name'] . '</td>
<td class="text-end">$' . $product['price'] * $product['quantity'] . '</td>';
}
echo '<tr>
<td class="text-left">Cart Subtotal</td>
<td class="text-end">$ ' . $subTotal . '</td>
</tr>
<tr>
<td class="text-left">Vat</td>
<td class="text-end">$ ' . $vat . '</td>
</tr>
<tr>
<td class="text-left">Cart Total</td>
<td class="text-end">$ ' . $total . '.00</td>
</tr>
<tr>
<td class="text-left">Order Total</td>
<td class="text-end">$' . $subTotal + $total + $vat . '</td>
</tr>';
}
?>
</tbody>
</table>
</div>
</div>
<!-- payment-method -->
<div class="col-md-6">
<div class="payment-method mt-60 pl-20">
<h4 class="title-1 title-border text-uppercase mb-30">payment and shipping
method</h4>
<div class="payment-accordion">
<form action="" method="post" enctype="multipart/form-data">
<input hidden type="text"
placeholder="Your name here..." name="fullname"
value="<?php echo $customer['fullname'] ?>">
<input hidden type="text"
placeholder="Email address here..." name="email"
value="<?php echo $customer['email'] ?>">
<input hidden type="text" placeholder="Phone here..."
name="phone"
value="<?php echo $customer['phone'] ?>">
<input hidden type="date" name="birthday"
placeholder="Birthday here..."
value="<?php echo $customer['birthday'] ?>">
<textarea hidden placeholder="Your address here..."
class="custom-textarea"
name="address"><?php echo $customer['address'] ?></textarea>
<select class="custom-select mb-15"
name="payment_method_id">
<?php
// get all payment methods
$sql = "SELECT * FROM payment_method";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
}
?>
</select>
<select class="custom-select mb-15"
name="shipping_method_id">
<?php
// get all payment methods
$sql = "SELECT * FROM shipping_method where status > 0";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
}
?>
</select>
<?php
$orderTotal = $total + $subTotal + $vat;
if (isset($_SESSION['cart'])) {
foreach ($_SESSION['cart'] as $product) {
echo '<input hidden type="text" name="product_id[]" value="' . $product['id'] . '">
<input hidden type="text" name="quantity[]" value="' . $product['quantity'] . '">';
}
}
echo '<input hidden type="text" name="subTotal" value="' . $subTotal . '">
<input hidden type="text" name="vat" value="' . $vat . '">
<input hidden type="text" name="total" value="' . $total . '">
<input hidden type="text" name="orderTotal" value="' . $orderTotal . '">';
?>
<button type="submit" class="button-one submit-button mt-15"
data-text="place order"
name="submit">place order</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- check-out end -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- CHECKOUT-AREA END -->
<!-- FOOTER START -->
<?php include_once 'elements\footer.php' ?>
<!-- FOOTER END -->
</div>
<!-- WRAPPER END -->
<!-- all js here -->
<?php include_once 'elements\js.php' ?>
</body>
</html>