-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproduct_detail.php
467 lines (438 loc) · 21.8 KB
/
product_detail.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
<?php
ob_start();
session_start();
$rootPath = '/ananas';
require_once './database/DB.php';
if (isset($_GET['productId'])) {
settype($_GET['productId'], 'int');
$productId = $_GET['productId'];
}
$sqlFindProduct = "SELECT * FROM product, product_instock, category WHERE product.product_id = '$productId' AND product.product_id = product_instock.product_id AND product.category_id = category.category_id LIMIT 1";
$sqlFindListPair = "SELECT size, quantity FROM product_instock WHERE product_id = '$productId'";
$pairList = $conn->query($sqlFindListPair);
$pairListArray = $pairList->fetch_all(MYSQLI_ASSOC);
$product = $conn->query($sqlFindProduct);
?>
<?php
require './includes/header.php';
require './includes/navbar.php';
if ($product->num_rows > 0) {
//start loop while
while ($row = $product->fetch_assoc()) {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $row["name"]; ?></title>
<link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.1.2/css/all.css">
<link rel="icon" type="image/x-icon" href="https://brademar.com/wp-content/uploads/2022/09/Ananas-Logo-PNG-1.png">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link rel="stylesheet" href="./public/css/base.css">
<style>
.sub_image {
cursor: pointer
}
.test-label {
font-weight: bold;
font-size: 1.5rem;
}
.hover-bg-black:hover {
background-color: black !important;
}
#addCartButton:hover {
background-color: orange !important;
border: none;
}
</style>
</head>
<body>
<section class="bg-light">
<div class="container pb-5">
<div class="row">
<div class="col-lg-6 mt-5">
<div class="card mb-3">
<img class="card-img rounded img-fluid" id="product-detail" alt="bla"
src="./public/img/<?php echo $row["images"] ?>">
</div>
<div class="row">
<div id="multi-item-example" class="carousel slide carousel-multi-item" data-bs-ride="carousel">
<!--Start Slides-->
<div class="carousel-inner product-links-wap" role="listbox">
<!--First slide-->
<div class="carousel-item active">
<div class="row">
<div class="col-3">
<img class="sub_image card-img img-fluid"
src="./public/img/<?php echo $row["subimg_1"] ?>" alt="Product Image 1">
</div>
<div class="col-3">
<img class="sub_image card-img img-fluid"
src="./public/img/<?php echo $row["subimg_2"] ?>" alt="Product Image 2">
</div>
<div class="col-3">
<img class="sub_image card-img img-fluid"
src="./public/img/<?php echo $row["subimg_3"] ?>" alt="Product Image 3">
</div>
<div class="col-3">
<img class="sub_image card-img img-fluid"
src="./public/img/<?php echo $row["images"] ?>" alt="Product Image 3">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- col end -->
<div class="col-lg-6 mt-5">
<div class="card">
<div class="card-body">
<h2 style="color:#002A54"><?php echo $row["name"]; ?> <span
class="text-secondary">#<?php echo $row["product_id"]; ?></span></h2>
<p class="h3 py-2" id="price">
<?php
// Nếu có giá Khuyến mãi
if ($row["price_sale"] != 0) {
echo '<del class="text-secondary">' . number_format($row["price"]) . '</del><sup>đ</sup>';
echo '<strong><span class="text-danger ms-3">' . number_format($row["price_sale"]) . '<sup>đ</sup></span></strong>';
?>
<span class="ms-3 bg-danger text-danger bg-opacity-25 rounded">
<?php
echo '-' . (int)(100 - ($row['price_sale'] / $row['price']) * 100) . '%';
?>
</span>
<?php
} else {
echo '<strong>' . number_format($row["price"]) . '<sup>đ</sup></strong>';
}
?>
</p>
<div>
<h3 class="text-warning text-uppercase">thông tin sản phẩm</h3>
<ul class="list-unstyled">
<li>
<span>Type: <?= $row['category_name'] ?></span>
</li>
<li>
<span>Gender: <?= $row['gender'] ?></span>
</li>
<li>
Size run:
</li>
<li>
Upper: <?php echo $row['upper_material'] ?>
</li>
<li>
Outsole: <?php echo $row['outsole_material'] ?>
</li>
</ul>
</div>
<h3 class="text-warning text-uppercase">Mô tả chi tiết:</h3>
<p><?php echo $row["description"] ?></p>
<?php
if ($row["quantity"] > 0) {
?>
<div class="pb-3">
<span class="badge bg-success" id="product-quantity">Còn <?php echo $row['quantity'] ?>
sản phẩm </span>
</div>
<?php
} else {
?>
<div class="pb-3">
<span class="badge bg-danger" href="#">Hết hàng tạm thời</span>
</div>
<?php
}
?>
<form action="process_cart.php" accept-charset="UTF-8" method="get">
<div class="row">
<ul class="list-inline mb-3 equal-width row">
<li class="list-inline-item col-5">
<label class="form-label text-uppercase test-label"
for="cart_item_product_stock">Size</label>
<select id="pickSize" class="selectpicker bs-select-hidden p-2"
data-style="btn" name="size">
<?php
foreach ($pairListArray as $pair) {
echo '<option value="' . $pair['size'] . '">' . $pair['size'] . '</option>';
}
?>
</select>
</li>
<li class="list-inline-item col-5">
<label class="form-label text-uppercase test-label" for="pickQuantity">Số
lượng</label>
<!--<select id="pickQuantity" class="selectpicker p-2" data-style="btn"
name="quantity">
</select>
Quantity increment buttons -->
<div class="input-group">
<span class="input-group-btn">
<button type="button" class="hover-bg-black text-white bg-primary btn btn-default btn-number rounded-0" id = "decButt" data-type="minus" data-field="quantity" onClick = "subQuantity()">
-
</button>
</span>
<input type="number" id="pickQuantity" class="form-control input-number ml-3 mr-3 text-center" name = "quantity" value="1" min="1" max="10">
<span class="input-group-btn">
<button type="button" class="hover-bg-black text-white bg-primary btn btn-default btn-number rounded-0" id = "incButt" data-type="plus" data-field="quantity" onClick = "addQuantity()">
+
</button>
</span>
</div>
</li>
</ul>
</div>
<input type="hidden" name="action" value="add">
<input type="hidden" name="id" value="<?php echo $row['product_id']?>">
<button id="addCartButton"
onclick="addCartItem(<?= $row['product_id'] ?>, document.getElementById('pickSize').value)"
class="d-flex align-items-center justify-content-center gap-2 text-uppercase w-100 py-3 bg-black text-white <?php if ($row["quantity"] <= 0) echo 'disabled' ?>">
<h4>thêm vào giỏ hàng</h4>
<i class="fa-solid fa-cart-shopping"></i>
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<?php
}
// end loop while
} else {
header("location: 404.php");
}
?>
<?php
// lấy userId hiện tại
if (isset($_SESSION['email_user']) && !empty($_SESSION['email_user'])) {
$email = $_SESSION['email_user'];
$sqlFindUser = "SELECT user_id FROM user WHERE email = '$email'";
$ketQua = $conn->query($sqlFindUser);
$user = $ketQua->fetch_array();
$userId = $user['user_id'];
}
$sqlReviews = "SELECT user.user_id, name, title, content, review.updated_at FROM review, user WHERE user.user_id = review.user_id AND review.product_id = '$productId'";
$review = $conn->query($sqlReviews);
if ($review->num_rows > 0) {
?>
<div class="container card mt-5 mb-5">
<div class="row">
<div class="ps-3 pe-3 pt-2">
<h3 class="border-bottom border-secondary pb-3">Đánh giá sản phẩm</h3>
</div>
</div>
<div class="row">
<?php
while ($row = $review->fetch_assoc()) {
?>
<!-- Review -->
<div class="ps-3 pe-3 pt-2">
<div class="media-body border-bottom border-secondary">
<span class="h4"><?= $row['name'] ?></span>
<?php
$userIdSelf = $row['user_id'];
$sqlUserOrder = "SELECT user_id FROM `ltweb`.`order`, order_item WHERE user_id = '$userIdSelf' AND product_id = '$productId' AND order.order_id = order_item.order_id";
$checkBuy = $conn->query($sqlUserOrder);
if ($checkBuy->num_rows > 0) {
echo '<span class="text-success"><i class="fa-duotone fa-badge-check"></i> Đã mua sản phẩm này</span>';
}
?>
<p class="mt-3 ms-2">
<span class="text-success"><?= $row['title'] ?></span>:
<?= $row['content'] ?>
</p>
<p class="ms-2"><i class="fa-light fa-clock"></i> <small><?= $row['updated_at'] ?></small></p>
</div>
</div>
<?php
}
?>
<div class="ps-3 pe-3 pt-3 pb-3">
<button type="button"
class="btn btn-primary <?php if (!isset($_SESSION['email_user'])) echo 'disabled' ?>"
data-bs-toggle="modal" data-bs-target="#postReview"><i class="fa-sharp fa-solid fa-circle-star"></i>
Viết đánh giá</button>
<!-- <button class="ms-1 btn btn-outline-primary">Xem đánh giá <i class="fa-light fa-circle-play"></i></button> -->
<div class="mt-1">
<i><small>(<i class="fa-regular fa-asterisk"></i>) Vui lòng đăng nhập để đánh giá sản phẩm
này</small></i>
</div>
</div>
</div>
</div>
<?php
} else {
?>
<div class="container card mt-5 mb-5">
<div class="row">
<div class="ps-3 pe-3 pt-2">
<h3 class="border-bottom border-secondary pb-3">Hãy là người đầu tiên đánh giá sản phẩm này</h3>
</div>
</div>
<div class="row">
<div class="ps-3 pe-3 pt-3 pb-3">
<button type="button"
class="btn btn-primary <?php if (!isset($_SESSION['email_user'])) echo 'disabled' ?>"
data-bs-toggle="modal" data-bs-target="#postReview"><i class="fa-sharp fa-solid fa-circle-star"></i>
Viết đánh giá</button>
<!-- <button class="ms-1 btn btn-outline-primary">Xem đánh giá <i class="fa-light fa-circle-play"></i></button> -->
</div>
</div>
<div class="row">
<div class="ps-3 pe-3 pb-3">
<i><small>(<i class="fa-regular fa-asterisk"></i>) Vui lòng đăng nhập để đánh giá sản phẩm
này</small></i>
</div>
</div>
</div>
<?php
}
?>
<div class="modal fade" id="postReview" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<form action="<?= $rootPath ?>/customer/reviews/add.php" method="post">
<input type="hidden" name="userId" value="<?= $userId ?>">
<input type="hidden" name="productId" value="<?= $productId ?>">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Đánh giá sản phẩm</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="titleReview" class="form-label">Tiêu đề</label>
<input type="text" class="form-control" id="titleReview" name="title"
placeholder="Mời nhập tiêu đề">
</div>
<div class="form-floating">
<textarea class="form-control" placeholder="Leave a comment here" name="content"
id="content" style="height: 100px"></textarea>
<label for="content">Đánh giá</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Đóng</button>
<button type="submit" name="review" class="btn btn-primary">Gửi</button>
</div>
</div>
</form>
</div>
</div>
<?php
$conn->close();
require './includes/footer.php';
?>
<!-- JavaScript Bundle with Popper -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"
integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous">
</script>
<script src="./public/javascripts/loadCartHeader.js"></script>
<script>
window.onload = function() {
var selectedOption = document.getElementById('pickQuantity').value;
var addCartButton = document.getElementById('addCartButton');
if (selectedOption === "") {
addCartButton.disabled = true;
}
};
var sizeQuantityPairs = <?php echo json_encode($pairListArray); ?>;
document.getElementById('pickSize').addEventListener('change', function() {
var selectedSize = this.value;
var quantity = sizeQuantityPairs.find(function(pair) {
return pair.size == selectedSize;
}).quantity;
var quantityStock = document.getElementById('product-quantity');
quantityStock.innerHTML = 'Còn ' + quantity + ' sản phẩm';
var quantitySelect = document.getElementById('pickQuantity');
quantitySelect.max = quantity;
console.log(quantitySelect.max)
quantitySelect.innerHTML = '<option selected=""> </option>';
for (var i = 1; i <= quantity; i++) {
quantitySelect.innerHTML += '<option value="' + i + '">' + i + '</option>';
}
});
document.getElementById('pickQuantity').addEventListener('change', function() {
var selectedOption = this.value;
console.log(this.value + " " + this.max + (this.value >= this.max))
if (Number(this.value) <= Number(this.min)) {
this.value = this.min
return
}
if (Number(this.value) >= Number(this.max)) {
this.value = this.max
return
}
var addCartButton = document.getElementById('addCartButton');
if (Number(this.value) >= Number(this.max)) {
addCartButton.disabled = true;
} else {
addCartButton.disabled = false;
}
});
function addQuantity(){
var quantitySelect = document.getElementById('pickQuantity');
quantitySelect.value = Number(quantitySelect.value) + 1;
if (Number( quantitySelect.value) >= Number(quantitySelect.max)) {
quantitySelect.value = quantitySelect.max
return
}
}
function subQuantity(){
var quantitySelect = document.getElementById('pickQuantity');
quantitySelect.value = Number(quantitySelect.value) - 1;
if (Number( quantitySelect.value) <= Number(quantitySelect.min)) {
quantitySelect.value = quantitySelect.min
return
}
}
function addCartItem(pId, size) {
var id = pId + "_" + size;
console.log(id);
$.ajax({
url: "<?= $rootPath ?>/ajax/loadCart.php",
type: "POST",
data: {
productId: id,
},
success: function(data) {
alert("Thêm sản phẩm thành công");
loadCartAjax();
},
error: function() {
alert("Lỗi thao tác");
}
});
}
$(document).ready(function() {
$('.sub_image').click(function() {
var src = $(this).attr('src');
$('#product-detail').attr('src', src);
});
});
$(document).ready(function() {
loadCartAjax();
$(window).scroll(
function() {
if ($(this).scrollTop() > 114) {
$("#navbar-top").addClass('fix-nav')
} else {
$("#navbar-top").removeClass('fix-nav')
}
}
)
});
</script>
<script src="./public/javascripts/liveSearch.js"></script>
</body>
</html>