-
Notifications
You must be signed in to change notification settings - Fork 1
/
giohang.php
267 lines (252 loc) · 9.36 KB
/
giohang.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
260
261
262
263
264
265
266
267
<?php include './inc/handle.php' ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- <link rel="stylesheet" href="assets/css/base.css"> -->
<link rel="stylesheet" href="assets/css/grid.css">
<link rel="stylesheet" href="assets/css/productCart.css">
<link rel="stylesheet" href="assets/css/base.css">
<link rel="stylesheet" href="assets/css/main.css">
<link rel="stylesheet" href="assets/font/themify-icons/themify-icons.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<title>Giỏ hàng</title>
</head>
<?php
// Cập nhập số lượng sản phẩm vào giỏ hàng
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['click_+'])) {
$cartId = $_POST['cartId'];
$quantity = $_POST['quantity_+'];
$update_quantity = $cat->updateQuantity($cartId, $quantity, Session::get('user_id'));
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['click_-'])) {
$cartId = $_POST['cartId'];
$quantity = $_POST['quantity_-'];
$update_quantity = $cat->updateQuantity($cartId, $quantity, Session::get('user_id'));
}
// Xóa sản phẩm ra khỏi giỏ hàng
if (isset($_GET['cartID'])) {
$cartId = $_GET['cartID'];
$delProductCart = $cat->del_ProductCart($cartId, Session::get('user_id'));
}
if (!isset($_GET['id'])) {
echo "<meta http-equiv='refresh' content='0;URL=?id=live'>";
}elseif($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id'])){
$id=$_POST['id'];
}
?>
<body>
<div class="grid">
<!-- Phần header -->
<?php include 'inc/header.php' ?>
</div>
<div class="grid" style="border-top: 1px solid #ccc;">
<div class="app">
<div class="grid wide">
<div class="app_cart">
<div class="row">
<div class="col l-8 " style="margin-top: 40px;">
<div class="col l-12">
<div class="checkout-process-bar block-border">
<ul>
<li class="active">
<span>Giỏ hàng</span>
</li>
<li class=""><span>Đặt hàng</span></li>
<li class=""><span>Thanh toán</span></li>
<li><span>Hoàn thành đơn</span></li>
</ul>
</div>
</div>
<div class="col l-12">
<h1 style="margin: 20px;font-weight: 600;font-size: 24px;line-height: 32px;color: #221f20;font-family: var(--font-family-sans-serif);">Giỏ hàng của bạn </h1>
</div>
<div class="col l-12 dal">
<table>
<thead>
<tr>
<th>Ảnh sản phẩm</th>
<th>Tên Sản Phẩm</th>
<th>Size</th>
<th>Giá</th>
<th>Số lượng</th>
<th>Số tiền</th>
<th>Trạng thái</th>
</tr>
</thead>
<tbody>
<?php
$getProductCat = $cat->getProductCart(Session::get('user_id'));
if ($getProductCat) {
$dem = 0;
$subTotal = 0;
$i = 0;
while ($result_ProductCat = $getProductCat->fetch_assoc()) {
$i++;
?>
<tr>
<td>
<div class="cart-td_title">
<img src="./admin/upload/<?php echo $result_ProductCat['image'] ?>" alt="" class="app_cart-img">
</div>
</td>
<td>
<span><?php echo $result_ProductCat['productName'] ?></span>
</td>
<td>
<?php echo $result_ProductCat['size'] ?>
</td>
<td>
<div class="cart-btn">
<span><?php echo number_format($result_ProductCat['price'], 0, ',', '.') . "" . "đ" ?></span>
</div>
</td>
<td>
<form action="" method="post">
<div class="quantity" style="display: flex;">
<input type="submit" class="btn" value="-" name="click_-" style="width:30px;">
<input type="hidden" name="cartId" value="<?php echo $result_ProductCat['cartID'] ?>" />
<?php
$get_productDetails = $product->getProduct_Details($result_ProductCat['productId']);
while ($result_Details = $get_productDetails->fetch_assoc()) {
if($result_ProductCat['quantity'] < $result_Details['quantity']){
?>
<input type="hidden" name="quantity_+" value="<?= $result_ProductCat['quantity'] + 1 ?>" id="hidden_input<?php echo $i; ?>" />
<?php
}else{
?>
<input type="hidden" name="quantity_+" value="<?= $result_ProductCat['quantity'] ?>" id="hidden_input<?php echo $i; ?>" />
<?php
}}
?>
<?php if ($result_ProductCat['quantity'] == 1) { ?>
<input type="hidden" name="quantity_-" value="<?= $result_ProductCat['quantity'] ?>" id="hidden_input<?php echo $i; ?>" />
<?php
} else {
?>
<input type="hidden" name="quantity_-" value="<?= $result_ProductCat['quantity'] - 1 ?>" id="hidden_input<?php echo $i; ?>" />
<?php
}
?>
<input type="hidden" name="id" value="<?= $result_ProductCat['productId']?>" id="hidden_input<?php echo $i; ?>" />
<input class="input" id="id<?php echo $i; ?>" type="text" value="<?= $result_ProductCat['quantity'] ?>" readonly="readonly" style="width:50px; text-align:center;">
<?php
$get_productDetails = $product->getProduct_Details($result_ProductCat['productId']);
while ($result_Details = $get_productDetails->fetch_assoc()) {
if($result_ProductCat['quantity'] < $result_Details['quantity']){
?>
<input type="submit" class="btn" value="+" name="click_+" style="width:30px;">
<?php
}else{
?>
<input type="button" onclick="warning()" class="btn" value="+" name="click_+" style="width:30px;">
<?php
}}
?>
</div>
</form>
</td>
<td>
<span class="cart-current"><?php $total = $result_ProductCat['price'] * $result_ProductCat['quantity'];
echo number_format($total, 0, ',', '.') . "" . "đ";
?></span>
</td>
<td>
<a onclick="return confirm('Bạn có chắc chắn muốn xóa')" href="?cartID=<?php echo $result_ProductCat['cartID'] ?>" class="ti-close"><?php ?></a>
</td>
</tr>
<?php
$dem++;
$subTotal += $total;
}
}
?>
</tbody>
<?php
if (isset($update_quantity)) {
echo $update_quantity;
}
?>
<?php
if (isset($delProductCart)) {
echo $delProductCart;
}
?>
</table>
</div>
<div class="col l-12">
<a class="back-history" href="javascript: window.history.back();">
<span class="ti-arrow-left" style="padding: 0 10px;">
</span>
Tiếp tục mua hàng
</a>
</div>
</div>
<div class="col l-4">
<div class="cart-voucher">
<h3>Tổng tiền giỏ hàng</h3>
<?php
$check_cart = $cat->checkCart(Session::get('user_id'));
if ($check_cart) {
?>
<div style="display: flex;justify-content: space-between; margin: 20px 0;">
<span class="voucher-title">
<span>Tổng sản phẩm</span>
</span>
<span class="sum-product"><?php
Session::set('sum', $dem);
echo $dem ?>
</span>
</div>
<div style="display: flex;justify-content: space-between; margin: 20px 0;">
<div class="voucher-title">
<span>Tổng tiền hàng</span>
</div>
<span class="sum-product"><?php echo number_format($subTotal, 0, ',', '.') . "" . "đ" ?></span>
</div>
<div style="display: flex;justify-content: space-between; margin: 20px 0;">
<span class="sum-product">Tiền thuế(VAT 10%)</span>
<span class="sum-product">
<?php
$vat = $subTotal * 0.1;
echo number_format($vat, 0, ',', '.') . "" . "đ";
?>
</span>
</div>
<div class="cart-purchase">
<span class="sum-product">Thành tiền</span>
<span class="sum-product" style="font-weight: 800;">
<?php
$grand_Total = $subTotal - $vat;
echo number_format($grand_Total, 0, ',', '.') . "" . "đ"
?>
</span>
</div>
<div class="cart-purchase-button">
<a href="thanhtoan.php"><button>Mua hàng</button></a>
</div>
<?php
} else {
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include './inc/footer.php' ?>
<script type="text/javascript">
function warning(){
Swal.fire({
icon: 'warning',
title: 'Oops...',
text: 'Đã đạt số lượng tối đa',
})
}
</script>
</body>
</html>