-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheach_product_view.php
428 lines (424 loc) · 20.1 KB
/
each_product_view.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
<?php
session_start();
include('config/dbcon.php');
include('components/header.php');
include('components/navbar.php');
include('components/frontbar.php');
if (isset($_GET['product'])) {
$product_number = $_GET['product'];
$product_query = "SELECT * FROM products WHERE incremented_name = '$product_number' LIMIT 1";
$result = mysqli_query($connection, $product_query);
if ($result && mysqli_num_rows($result) > 0) {
$product = mysqli_fetch_assoc($result);
// $product["id"];
// $product["product_name"];
// $product["incremented_name"];
// $product["product_description"];
// $product["price"];
// $product["quantitty"];
// $product["image_1"];
// $product["category_id"];
?>
<main class="product_page_container">
<div class="product_navigation">
<?php
if (isset($_GET['page_name']) && isset($_GET['category'])) {
$page_name = $_GET['page_name'];
$go_back_category = $_GET['category'];
?>
<p><a href="home.php">Home </a>/ <a href="<?= $page_name; ?>.php?category=<?= $go_back_category; ?>">Browse by Category </a> / <span class="prod_name_disable"><?= $product["product_name"]; ?></span></p>
<?php
} else if (isset($_GET['page_name'])) {
$page_name = $_GET['page_name'];
?>
<p><a href="home.php">Home </a>/ <a href="<?= $page_name; ?>.php?">Shop All </a> / <span class="prod_name_disable"><?= $product["product_name"]; ?></span></p>
<?php
} else {
?>
<p><a href="home.php">Home </a>/ <span class="prod_name_disable"><?= $product["product_name"]; ?></span></p>
<?php
}
?>
</div>
<div class="product_details" style="background-color: white;">
<div class="product_details1">
<div class="product_image_container">
<img src="admin/uploads/<?= $product["image_1"]; ?>" alt="<?= $product["image_1"]; ?>">
</div>
</div>
<div class="product_details2">
<div class="product_name_container">
<p class="product-name1"><?= $product["product_name"]; ?></p>
</div>
<div class="product_incremented_container">
<p>SKU: <?= $product["incremented_name"]; ?></p>
</div>
<div class="product_price_container">
<p>R<?= $product["price"]; ?></p>
</div>
<!-- Product {quantity, cart, wishList, buyNow and no_stock}-->
<form action="functions/handle_cart.php" method="post">
<!-- product quantity-->
<div class="quantity_container">
<label for="quantity">Quantity</label>
<input type="number" class="cart_add_qty" value="1" name="quantity" id="quantity" min="1">
</div>
<?php
/* cart, wishList, buyNow and no_stock_container*/
if ($product["quantitty"] != 0) {
?>
<div class="cart_wish_container">
<input type="hidden" name="product_id" value="<?= $product["id"]; ?>">
<input type="hidden" name="stock_qty" value="<?= $product["quantitty"]; ?>">
<input type="hidden" name="SKU" value="<?= $product_number; ?>">
<input type="hidden" name="page" value="product_view">
<input class="add_product_button-js" type="submit" value="Add to Cart" name="add_to_cart-btn"></input>
<button type="submit" class="whishlist" name="add_whish_btn"><img src="https://img.icons8.com/pastel-glyph/64/751fff/like--v2.png" alt="like--v2" /></button>
</div>
<div class="buy_container">
<input type="submit" value="Buy Now" name="buy_now-btn"></input>
</div>
<?php
/* no_stock_container*/
} else {
?>
<div class="no_stock_container">
<button class="disabled_btn" disabled>Out of Stock</button>
<input type="hidden" name="product_id" value="<?= $product["id"]; ?>">
<input type="hidden" name="SKU" value="<?= $product_number; ?>">
<button type="submit" class="whishlist" name="add_whish_btn"><img src="https://img.icons8.com/pastel-glyph/64/751fff/like--v2.png" alt="like--v2" /></button>
</div>
<?php
}
?>
</form>
<div class="product_info_container">
<div class="info_dropdown"><span>Product Info</span><span class="sign sign1-js">+</span></div>
<div class="info_content_off">
<p>I'm a product detail. I'm a great place to add more information about your product such as sizing, material, care and cleaning instructions. This is also a great space to write what makes this product special and how your customers can benefit from this item.</p>
</div>
<hr>
<div class="descr_dropdown"><span>Product Description</span><span class="sign sign2-js">+</span></div>
<div class="descr_content_off">
<p><?= $product["product_description"]; ?></p>
</div>
<hr>
<ul class="points">
<li>Eligible for Cash on Delivery.</li>
<li>Hassle-Free Exchanges</li>
<li>Returns for 30 Days.</li>
<li>6-Month Limited Warranty.</li>
</ul>
</div>
</div>
</div>
<div class="product_reviews horiz_ruler">
<?php
$id = $product["id"];
$check_reviews = "SELECT reviews.*, users.username as user_name FROM reviews
JOIN users ON reviews.user_id = users.id
WHERE reviews.product_id = '$id'";
$check_reviews_run = mysqli_query($connection, $check_reviews);
if ($check_reviews_run && mysqli_num_rows($check_reviews_run) > 0) {
?>
<div class="info_dropdown horiz_ruler">
<span>Reviews</span>
</div>
<hr>
<div class="product_reviews_container">
<div class="review_list_container">
<?php
$count = 0;
$rating = 0;
foreach ($check_reviews_run as $items) {
$rating = $rating + $items["rating"];
$count++;
?>
<div class="review_list">
<div class="review_list_header">
<p><b><?= $items["user_name"]; ?> - <?= date('Y-m-d', strtotime($items["created_at"])); ?></b></p>
<?php
if (isset($_SESSION['auth_user'])) {
if ($_SESSION['auth_user']['username'] == $items["user_name"]) {
?>
<div class="open_close">
<img src="https://img.icons8.com/ios-filled/50/menu-2.png" alt="menu-2" />
<div class="dropdown_content_off">
<button class="dropdown-item open_edit">Edit</button>
<hr>
<form action="functions/handle_review.php" method="post">
<input type="hidden" name="SKU" value="<?= $product_number; ?>">
<input type="hidden" name="product_id" value="<?= $product["id"]; ?>">
<button type="submit" class="dropdown-item" name="delete_btn" href="#">Delete</button>
</form>
</div>
</div>
<?php
}
}
?>
</div>
<p>
<?php
for ($index = 0; $index < $items["rating"]; $index++) {
?>
<img width="14" height="14" src="https://img.icons8.com/forma-light-filled/24/751fff/star.png" alt="star" />
<?php
}
for ($index = 0; $index < (5 - $items["rating"]); $index++) {
?>
<img width="15" height="15" src="https://img.icons8.com/forma-bold-filled/24/737373/star.png" alt="star" />
<?php
}
?>
</p>
<p><b><?= $items["title"]; ?></b></p>
<p><?= $items["content"]; ?></p>
<div class="image_container"><img src="uploads/<?= $items["image"]; ?>" alt="<?= $items["title"]; ?>"></div>
<div class="helpful">
<span class="space">Was this helpful?</span>
<img width="20" height="20" src="https://img.icons8.com/ios/50/facebook-like--v1.png" alt="facebook-like--v1" />
<span class="space">Yes</span>
<img width="20" height="20" src="https://img.icons8.com/wired/64/reply.png" alt="reply" />
<span class="space">Reply</span>
</div>
</div>
<?php
}
?>
</div>
<div class="review_rating_container">
<h3>Rating Block</h3>
<div>
<?php
$avg = $rating / $count;
$floor_avg = floor($avg);
if ($floor_avg == $avg) {
for ($index = 0; $index < $floor_avg; $index++) {
?>
<img width="14" height="14" src="https://img.icons8.com/forma-light-filled/24/751fff/star.png" alt="star" />
<?php
}
for ($index = 0; $index < (5 - $floor_avg); $index++) {
?>
<img width="15" height="15" src="https://img.icons8.com/forma-bold-filled/24/737373/star.png" alt="star" />
<?php
}
} else {
for ($index = 0; $index < $floor_avg; $index++) {
?>
<img width="14" height="14" src="https://img.icons8.com/forma-light-filled/24/751fff/star.png" alt="star" />
<?php
}
?>
<img width="15" height="15" src="https://img.icons8.com/material-rounded/24/751fff/star-half-empty.png" alt="star-half-empty" />
<?php
for ($index = 0; $index < (4 - $floor_avg); $index++) {
?>
<img width="15" height="15" src="https://img.icons8.com/forma-bold-filled/24/737373/star.png" alt="star" />
<?php
}
}
?>
<?= number_format(($rating / $count), 1); ?>
</div>
<p>Based on <?= $count; ?> review</p>
<button class="Leave_review_js write_review">Write a Review</button>
<div class="product_review_form update_off">
<form enctype="multipart/form-data" action="functions/handle_review.php" method="post">
<div class="form_group">
<label for="review_rating">Rating*</label>
<select id="review_rating" name="review_rating">
<option value="1">1 star</option>
<option value="2">2 stars</option>
<option value="3">3 stars</option>
<option value="4">4 stars</option>
<option value="5">5 stars</option>
</select>
</div>
<div class="form_group">
<label for="review_title">Review Title*</label>
<input type="text" id="review_title" name="review_title" maxlength="350">
</div>
<div class="form_group">
<label for="review_content">Review*</label>
<textarea rows="4" id="review_content" name="review_content" maxlength="500"></textarea>
</div>
<div class="form_group">
<label for="review_media">Add images & videos (1/1)</label>
<div class="file-input-container">
<input type="file" id="file-input" name="image" class="file-input" accept="image/*, video/*" multiple>
<label for="file-input" class="file-label">
<span class="file-icon">+</span>
<span class="file-text">Add File</span>
</label>
</div>
</div>
<div class="form_actions">
<input type="hidden" name="SKU" value="<?= $product["incremented_name"]; ?>">
<input type="hidden" name="product_id" value="<?= $product["id"]; ?>">
<button type="submit" name="update_review_btn" class="publish_review">Update Review</button>
</div>
</form>
</div>
<div class="product_review_form review_off_1">
<form enctype="multipart/form-data" action="functions/handle_review.php" method="post">
<div class="form_group">
<label for="review_rating">Rating*</label>
<select id="review_rating" name="review_rating">
<option value="1">1 star</option>
<option value="2">2 stars</option>
<option value="3">3 stars</option>
<option value="4">4 stars</option>
<option value="5">5 stars</option>
</select>
</div>
<div class="form_group">
<label for="review_title">Review Title*</label>
<input type="text" id="review_title" name="review_title" maxlength="350">
</div>
<div class="form_group">
<label for="review_content">Review*</label>
<textarea rows="4" id="review_content" name="review_content" maxlength="500"></textarea>
</div>
<div class="form_group">
<label for="review_media">Add images & videos (1/1)</label>
<div class="file-input-container">
<input type="file" id="file-input" name="image" class="file-input" accept="image/*, video/*" multiple>
<label for="file-input" class="file-label">
<span class="file-icon">+</span>
<span class="file-text">Add File</span>
</label>
</div>
</div>
<div class="form_actions">
<input type="hidden" name="SKU" value="<?= $product["incremented_name"]; ?>">
<input type="hidden" name="product_id" value="<?= $product["id"]; ?>">
<button type="submit" name="publish_review_btn" class="publish_review">Publish</button>
</div>
</form>
</div>
</div>
</div>
<?php
} else {
?>
<div class="no_review no_review_on">
<p>No Reviews Yet</p>
<p>Share your thoughts. Be the first to leave a review.</p>
<button onclick="switch_review_container();" class="Leave_review">Leave a Review</button>
</div>
<div class="product_review_form review_off">
<form enctype="multipart/form-data" action="functions/handle_review.php" method="post">
<div class="form_group">
<label for="review_rating">Rating*</label>
<select id="review_rating" name="review_rating">
<option value="1">1 star</option>
<option value="2">2 stars</option>
<option value="3">3 stars</option>
<option value="4">4 stars</option>
<option value="5">5 stars</option>
</select>
</div>
<div class="form_group">
<label for="review_title">Review Title*</label>
<input type="text" id="review_title" name="review_title" maxlength="350">
</div>
<div class="form_group">
<label for="review_content">Review*</label>
<textarea rows="4" id="review_content" name="review_content" maxlength="500"></textarea>
</div>
<div class="form_group">
<label for="review_media">Add images & videos (1/1)</label>
<div class="file-input-container">
<input type="file" id="file-input" name="image" class="file-input" accept="image/*, video/*" multiple>
<label for="file-input" class="file-label">
<span class="file-icon">+</span>
<span class="file-text">Add File</span>
</label>
</div>
</div>
<div class="form_actions">
<input type="hidden" name="SKU" value="<?= $product["incremented_name"]; ?>">
<input type="hidden" name="product_id" value="<?= $product["id"]; ?>">
<button type="button" onclick="switch_review_container();" class="cancel_review">Cancel</button>
<button type="submit" name="publish_review_btn" class="publish_review">Publish</button>
</div>
</form>
</div>
<?php
}
?>
</div>
<div class="product_recomendation">
<h3>You Might Also Like</h3>
<div class="">
<div class="best_sale_container">
<div class="best-sale-section">
<div class="product-container" id="product-container3">
<?php
$sql = "SELECT * FROM products";
$result = mysqli_query($connection, $sql);
if ($result) {
if (mysqli_num_rows($result) > 0) {
$count = 0;
foreach ($result as $items) {
if ($items["category_id"] == $product["category_id"] && $items["incremented_name"] != $product["incremented_name"]) {
?>
<div class="product">
<!--link to a specific product page-->
<a href="each_product_view.php?product=<?= $items["incremented_name"]; ?>">
<div class="image_container1"><img src="admin/uploads/<?= $items["image_1"]; ?>" alt="<?= $items["product_name"]; ?>"></div>
<p class="product-name"><?= $items["product_name"]; ?></p>
</a>
<p>
<?php
if ($items["quantitty"] != 0) {
?>
<span class="old-price">R305</span> <span class="product-price">R<?= $items["price"]; ?></span>
<?php
} else {
?>
<span class="old-price">Out of Stock</span>
<?php
}
?>
</p>
</div>
<?php
$count++;
if ($count >= 4) {
break;
}
}
}
} else {
?>
<div class="each_category">
<p>No Categories Avaliable!</p>
</div>
<?php
}
} else {
?>
<div class="each_category">
<p>Somehing Went Wrong! Sorry About that.</p>
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</main>
<?php
} else {
echo "Something went wrong!";
}
} else {
echo "Something went wrong!";
}
include('components/footer.php');
?>