-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheckout.php
259 lines (240 loc) · 12.6 KB
/
checkout.php
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
<?php include "./config/connect.php" ?>
<!-- Checkout Section Start -->
<div class="section section-margin">
<div class="container">
<div class="row m-b-n20">
<div class="col-lg-6 col-12 m-b-20" data-aos="fade-right">
<!-- Checkbox Form Start -->
<div class="checkbox-form">
<!-- Checkbox Form Title Start -->
<h3 class="title">Hoá Đơn Chi Tiết</h3>
<!-- Checkbox Form Title End -->
<form action="./backend/checkout.php" method="POST" id="checkoutForm" class="form-control">
<div class="row">
<?php
$user = $_SESSION['user'];
$sql = "SELECT * FROM `tb_user` WHERE username = '$user'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$fullname = $row['fullname'];
$email = $row['email'];
$phone = $row['phone'];
$address = $row['address'];
?>
<!-- First Name Input Start -->
<div class="col-md-6">
<div class="checkout-form-list">
<label for="fullname">Họ và tên <span class="required">*</span></label>
<input name="fullname" placeholder="Nhập họ và tên" type="text" value="<?php echo $fullname ?>" class="form-control">
</div>
</div>
<!-- First Name Input End -->
<!-- Last Name Input Start -->
<div class="col-md-6">
<div class="checkout-form-list">
<label for="phone">Điện Thoại <span class="required">*</span></label>
<input name="phone" placeholder="Nhập số điện thoại" type="text" value="<?php echo $phone ?>" class="form-control">
</div>
</div>
<!-- Last Name Input End -->
<!-- Address Input Start -->
<div class="col-md-12">
<div class="checkout-form-list">
<label for="address">Địa chỉ <span class="required">*</span></label>
<input name="address" placeholder="Nhập địa chỉ giao hàng" type="text" value="<?php echo $address ?>" class="form-control">
</div>
</div>
<!-- Address Input End -->
<!-- State or Country Input Start -->
<div class="col-md-6">
<div class="checkout-form-list">
<label for="province">Tỉnh <span class="required">*</span></label>
<input placeholder="Nhập tỉnh thành" type="text" name="province" class="form-control">
</div>
</div>
<!-- State or Country Input End -->
<!-- Town or City Name Input Start -->
<div class="col-md-6">
<div class="checkout-form-list">
<label for="city">Thành Phố <span class="required">*</span></label>
<input name="city" type="text" placeholder="Nhập thành phố" class="form-control">
</div>
</div>
<!-- Town or City Name Input End -->
<!-- Email Address Input Start -->
<div class="col-md-12">
<div class="checkout-form-list">
<label for="email">Email <span class="required">*</span></label>
<input name="email" placeholder="Nhập email nhận thông báo" type="email" value="<?php echo $email ?>" class="form-control">
</div>
</div>
<!-- Email Address Input End -->
</div>
<!-- Different Address End -->
<div class="order-button-payment">
<button class="btn btn-primary btn-hover-dark rounded-0 w-100" type="submit" name="submit">Đặt Hàng</button>
</div>
</div>
</form>
<!-- Checkbox Form End -->
</div>
<div class="col-lg-6 col-12 m-b-20" data-aos="fade-left">
<!-- Your Order Area Start -->
<div class="your-order-area border">
<!-- Title Start -->
<h3 class="title">Đơn hàng của bạn</h3>
<!-- Title End -->
<!-- Your Order Table Start -->
<div class="your-order-table table-responsive">
<table class="table">
<!-- Table Head Start -->
<thead>
<tr class="cart-product-head">
<th class="cart-product-name text-start">Sản phẩm</th>
<th class="cart-product-total text-end">Tổng tiền</th>
</tr>
</thead>
<!-- Table Head End -->
<!-- Table Body Start -->
<tbody>
<?php
$sql = "SELECT *
FROM `tb_cart` as c, `tb_product` as p
WHERE username = '$user'
AND c.id_product = p.id_product";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
$totalMoney = 0;
for ($i = 0; $i < $count; $i++) {
$row = mysqli_fetch_assoc($result);
$name = $row['name'];
$price = (float)$row['price'];
$amount = (int)$row['amount'];
$discout_price = $price * (100 - (int)$row['discount']) / 100;
$total = $discout_price * $amount;
$totalMoney += $total;
?>
<tr class="cart_item">
<td class="cart-product-name text-start ps-0"> <?php echo $name ?>
<strong class="product-quantity"> × <?php echo $amount ?></strong>
</td>
<td class="cart-product-total text-end pe-0">
<span class="amount"><?php echo $total ?>$</span>
</td>
</tr>
<?php
}
?>
</tbody>
<!-- Table Body End -->
<!-- Table Footer Start -->
<tfoot>
<tr class="cart-subtotal">
<th class="text-start ps-0">Tổng đơn hàng</th>
<td class="text-end pe-0"><strong><span class="amount"><?php echo $totalMoney ?>$</span></strong></td>
</tr>
</tfoot>
<!-- Table Footer End -->
</table>
</div>
<!-- Your Order Table End -->
<!-- Payment Accordion Order Button Start -->
<div class="payment-accordion-order-button">
<div class="payment-accordion">
<div class="single-payment">
<h5 class="panel-title m-b-15">
<a class="collapse-off" data-bs-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Thanh toán
</a>
</h5>
<div class="collapse show" id="collapseExample">
<div class="card card-body rounded-0">
<p>Chức năng thanh toán online hiện chưa phát triển, bạn chỉ có thể sử dụng thanh toán COD</p>
</div>
</div>
</div>
</div>
</div>
<!-- Payment Accordion Order Button End -->
</div>
<!-- Your Order Area End -->
</div>
</div>
</div>
</div>
<!-- Checkout Section End -->
<script type="text/javascript">
$(document).ready(() => {
$('#checkoutForm').validate({
rules: {
name: {
required: true,
minlength: 5
},
phone: {
required: true,
minlength: 10,
maxlength: 11
},
address: {
required: true,
minlength: 5
},
province: {
required: true,
minlength: 5
},
city: {
required: true,
minlength: 5
},
email: {
required: true,
email: true
}
},
messages: {
name: {
required: "Vui lòng nhập tên",
minlength: "Tên phải có ít nhất 5 ký tự"
},
phone: {
required: "Vui lòng nhập SĐT",
minlength: "SĐT phải có ít nhất 10 ký tự",
maxlength: "SĐT phải có tối đa 11 ký tự"
},
address: {
required: "Vui lòng nhập địa chỉ",
minlength: "Địa chỉ phải có ít nhất 5 ký tự"
},
province: {
required: "Vui lòng nhập tỉnh",
minlength: "Làm gì có tỉnh nào ngắn hơn 5 ký tự"
},
city: {
required: "Vui lòng nhập thành phố",
minlength: "Làm gì có thành phố nào ngắn hơn 5 ký tự"
},
email: {
required: "Vui lòng nhập email",
email: "Email không hợp lệ"
}
},
errorElement: 'div',
errorPlacement: (error, element) => {
error.addClass('invalid-feedback');
if (element.prop('type') === 'checkbox') {
error.insertAfter(element.siblings('label'));
} else {
error.insertAfter(element);
}
},
highlight: (element, errorClass, validClass) => {
$(element).addClass('is-invalid').removeClass('is-valid').show();
},
unhighlight: (element, errorClass, validClass) => {
$(element).addClass('is-valid').removeClass('is-invalid').show();
}
})
});
</script>