forked from HasiniSama/microtech-website
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproduct_page.php
394 lines (342 loc) · 18.2 KB
/
product_page.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
<?php
include "db_conn.php";
//get session variables
session_start();
if (isset($_SESSION['email'])) {
$email = $_SESSION['email'];
}
else if(isset($_SESSION['admin_email'])) {
$email = $_SESSION['admin_email'];
}
session_write_close();
//get product id using incoming url
$productId = $_GET['item'];
//get that product details from database
$sqlQuery = "SELECT * FROM items WHERE item_id = ".$productId;
$result = $conn->query($sqlQuery);
$product = $result->fetch_array();
//get same category products for related products section
$sqlQuery2 = "SELECT * FROM items WHERE category = '".$product['category']."' AND item_id != ".$productId;
$result2 = $conn->query($sqlQuery2);
//getting current stock values
$sqlQuery4 = "SELECT * FROM stock WHERE item_id = ".$productId;
$result4 = $conn->query($sqlQuery4);
$stockItem = $result4->fetch_array();
$no_of_items = $stockItem['no_of_items'];
if(isset($_REQUEST['submit']) && isset($_SESSION['email'])){
$qty = $_REQUEST['num-product'];
if($no_of_items >= $qty) {
//adding data to the cart
$sqlQuery3 = "INSERT INTO cart values ('" . $email . "','" . $productId . "','" . $qty . "')";
$result3 = $conn->query($sqlQuery3);
//update stock values
$new_no_of_items = $no_of_items - $qty;
$sqlQuery5 = "UPDATE stock SET no_of_items = " . $new_no_of_items . " WHERE item_id = " . $productId;
$result5 = $conn->query($sqlQuery5);
}
} // redirect user to sign in
else if(isset($_REQUEST['submit'])){
header("Location: signin_page.php?error=Please sign in to proceed!");
exit();
}
// update current stock values again
$result4 = $conn->query($sqlQuery4);
$stockItem = $result4->fetch_array();
$no_of_items = $stockItem['no_of_items'];
?>
<!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 $product['item_name'] ?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/utility.css">
<link rel="stylesheet" type="text/css" href="css/product.css">
<link rel="stylesheet" type="text/css" href="css/shopping_page.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
</head>
<body>
<!-- Header -->
<?php $page = 'product'; include 'include/header.php'; ?>
<!-- breadcrumb -->
<div class="container">
<div class="bread-crumb flex-w p-r-15 p-t-100">
<a href="index.php" class="stext-109 cl8 hov-cl1 trans-04">
Shop
<i class="fa fa-angle-right m-l-9 m-r-10" aria-hidden="true"></i>
</a>
<a href="shopping_page.php" class="stext-109 cl8 hov-cl1 trans-04">
<?php echo $product['category'] ?>
<i class="fa fa-angle-right m-l-9 m-r-10" aria-hidden="true"></i>
</a>
<span class="stext-109 cl4">
<?php echo $product['item_name'] ?>
</span>
</div>
</div>
<!-- Product Detail -->
<section class="sec-product-detail">
<div class="container single-product">
<div class="row">
<div class="col-md-6 col-lg-7 product-image">
<img src="<?php echo $product['img_name1'] ?>" id = "ProductImg" alt="PRODUCT-IMG">
<div class="small-img-row">
<div class="small-img-col">
<img src="<?php echo $product['img_name1'] ?>" alt="PRODUCT-IMG" class = "small-img">
</div>
<?php if($product['img_name2'] != NULL){ ?>
<div class="small-img-col">
<img src="<?php echo $product['img_name2'] ?>" alt="PRODUCT-IMG" class = "small-img">
</div>
<?php } ?>
<?php if($product['img_name3'] != NULL){ ?>
<div class="small-img-col">
<img src="<?php echo $product['img_name3'] ?>" alt="PRODUCT-IMG" class = "small-img">
</div>
<?php } ?>
<?php if($product['img_name4'] != NULL){ ?>
<div class="small-img-col">
<img src="<?php echo $product['img_name4'] ?>" alt="PRODUCT-IMG" class = "small-img">
</div>
<?php } ?>
</div>
</div>
<div class="col-md-6 col-lg-5 p-b-30">
<div class="product-section">
<h4 class="js-name-detail">
<?php echo $product['item_name'] ?>
</h4>
<span>
LKR <?php echo $product['item_price'] ?>/-
</span>
<p>
<?php echo $product['long_description'] ?>
</p>
<?php
if($no_of_items>0) { ?>
<p class = "in-stock"><?php echo "Item : <span>".$no_of_items." items in stock </span>" ?> </p>
<?php }
else{
echo "<p>Item : <span> Out of stock </span></p>";
}?>
<div class="product-details">
<div class="product-options">
<div class="product-amount">
<?php if($no_of_items>0) { ?>
<form id="form" name="form" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<div class="amount-counter">
<div class="btn-num-product-down">
<i class="fs-16 zmdi zmdi-minus"></i>
</div>
<input class="num-product" type="number" name="num-product" id="num-product" value="1">
<div class="btn-num-product-up">
<i class="fs-16 zmdi zmdi-plus"></i>
</div>
</div>
<button class="btn-add-cart add-to-cart-alert" name="submit" id="submit">
Add to cart
</button>
</form>
<?php }else{ ?>
<div class="amount-counter">
<div class="btn-num-product-out">
<i class="fs-16 zmdi zmdi-minus"></i>
</div>
<input class="num-product" type="number" name="num-product" id="num-product" value="1">
<div class="btn-num-product-out">
<i class="fs-16 zmdi zmdi-plus"></i>
</div>
</div>
<button class="btn-out-cart add-to-cart-alert">
Add to cart
</button>
<?php } ?>
</div>
</div>
</div>
<div class="addtional-options">
<div class="add-to-wishlist">
<a href="#" class="fs-14 cl3 hov-cl1 trans-04 lh-10 p-lr-5 p-tb-2 js-addwish-detail">
<i class="zmdi zmdi-favorite"></i>
</a>
</div>
<h6>Add to wishlist</h6>
</div>
</div>
</div>
</div>
<div class="product-desc-section">
<!-- Tab01 -->
<div class="tab01">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#description" role="tab">Description</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#information" role="tab">Additional information</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#reviews" role="tab">Reviews (1)</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane fade show active" id="description" role="tabpanel">
<div class="how-pos2">
<p>
<?php echo $product['long_description'] ?>
</p>
</div>
</div>
<div class="tab-pane fade" id="reviews" role="tabpanel">
<div class="row">
<div class="col-sm-10 col-md-8 col-lg-6 review-tab">
<div class="review-section">
<div class="other-reviews-section">
<div class="other-review">
<div class="header">
<span id="reviewer">
Krishan Shamod
</span>
<span id="rating">
<i class="zmdi zmdi-star"></i>
<i class="zmdi zmdi-star"></i>
<i class="zmdi zmdi-star"></i>
<i class="zmdi zmdi-star"></i>
<i class="zmdi zmdi-star-half"></i>
</span>
</div>
<p id="other-review">
Very phone. Much style. Stylish pen is exceptionally good. 10/10 would recommend.
</p>
</div>
</div>
<!-- Add a review -->
<form>
<h5>Add a review</h5>
<p> Your email address will not be published. Required fields are marked *</p>
<div id="your-rating">
<span class="your-rating-header">
Your Rating
</span>
<span class="wrap-rating">
<i class="item-rating pointer zmdi zmdi-star-outline"></i>
<i class="item-rating pointer zmdi zmdi-star-outline"></i>
<i class="item-rating pointer zmdi zmdi-star-outline"></i>
<i class="item-rating pointer zmdi zmdi-star-outline"></i>
<i class="item-rating pointer zmdi zmdi-star-outline"></i>
<input class="dis-none" type="number" name="rating">
</span>
</div>
<div class="row review-area">
<div class="col-12">
<label for="review">Your review</label>
<textarea id="review" name="review"></textarea>
</div>
<div class="col-sm-6 txt-box">
<label for="name">Name</label>
<input id="name" type="text" name="name">
</div>
<div class="col-sm-6 txt-box">
<label for="email">Email</label>
<input id="email" type="text" name="email">
</div>
</div>
<button class="btn-add-cart">
Submit
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Related Products -->
<section class="relate-product-section">
<div class="container">
<div class="relate-product-header">
<h3 class="ltext-103 cl2 txt-center">
Related Products
</h3>
</div>
<div class="row isotope-grid">
<!-- Products -->
<?php $count = 1;
while($row = $result2->fetch_array()){
if($count <=4 ){
?>
<div class="col-sm-6 col-md-4 col-lg-3 p-b-35 isotope-item">
<div class="block2">
<div class="block2-pic hov-img1">
<img src="<?php echo $row['img_name1'] ?>" alt="IMG-PRODUCT">
<a href="product_page.php?item=<?php echo $row['item_id'] ?>"
class="block2-btn flex-c-m stext-103 cl0 size-102 bg3 bor2 hov-btn2 p-lr-15 trans-04">
View
</a>
</div>
<div class="block2-txt flex-w flex-t p-t-14">
<div class="block2-txt-child1 flex-col-l ">
<a href="view.php" class="stext-104 cl4 hov-cl1 trans-04 p-b-6">
<?php echo $row['item_name'] ?>
</a>
<span class="stext-105 cl3">
LKR <?php echo $row['item_price'] ?>
</span>
</div>
<div class="block2-txt-child2 flex-r p-t-3">
<a href="#" class="btn-addwish-b2 dis-block pos-relative">
<img class="icon-heart1 dis-block trans-04" src="images/icons/icon-heart-01.png" alt="ICON">
<img class="icon-heart2 dis-block trans-04 ab-t-l" src="images/icons/icon-heart-02.png" alt="ICON">
</a>
</div>
</div>
</div>
</div>
<?php
$count++;
}
} ?>
</div>
</div>
</section>
<!-- Footer Section -->
<?php include 'include/footer.php'; ?>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://kit.fontawesome.com/bfc2cbc6c6.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<!-- <script>
$('.add-to-cart-alert').click(function(e){
var form = $(this).parents('#form');
e.preventDefault();
swal({
title: "<?php //echo $product['item_name'] ?>",
text: "Successfully added to cart!",
type: "success",
showCancelButton: true,
confirmButtonColor: '#717fe0',
closeOnConfirm: false,
closeOnCancel: false,
html: false
}).then(function (1) {
if (isConfirm) {
form.submit(); // <--- submit form programmatically
}
});
});
</script>-->
<script src="js/product.js"></script>
<script src="js/app.js"></script>
</body>
</html>