-
Notifications
You must be signed in to change notification settings - Fork 0
/
product-category.php
278 lines (258 loc) · 13.5 KB
/
product-category.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
<?php require_once('header.php'); ?>
<?php
$statement = $pdo->prepare("SELECT * FROM tbl_settings WHERE id=1");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$banner_product_category = $row['banner_product_category'];
}
?>
<?php
if( !isset($_REQUEST['id']) || !isset($_REQUEST['type']) ) {
header('location: index.php');
exit;
} else {
if( ($_REQUEST['type'] != 'top-category') && ($_REQUEST['type'] != 'mid-category') && ($_REQUEST['type'] != 'end-category') ) {
header('location: index.php');
exit;
} else {
$statement = $pdo->prepare("SELECT * FROM tbl_top_category");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$top[] = $row['tcat_id'];
$top1[] = $row['tcat_name'];
}
$statement = $pdo->prepare("SELECT * FROM tbl_mid_category");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$mid[] = $row['mcat_id'];
$mid1[] = $row['mcat_name'];
$mid2[] = $row['tcat_id'];
}
$statement = $pdo->prepare("SELECT * FROM tbl_end_category");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$end[] = $row['ecat_id'];
$end1[] = $row['ecat_name'];
$end2[] = $row['mcat_id'];
}
if($_REQUEST['type'] == 'top-category') {
if(!in_array($_REQUEST['id'],$top)) {
header('location: index.php');
exit;
} else {
// Getting Title
for ($i=0; $i < count($top); $i++) {
if($top[$i] == $_REQUEST['id']) {
$title = $top1[$i];
break;
}
}
$arr1 = array();
$arr2 = array();
// Find out all ecat ids under this
for ($i=0; $i < count($mid); $i++) {
if($mid2[$i] == $_REQUEST['id']) {
$arr1[] = $mid[$i];
}
}
for ($j=0; $j < count($arr1); $j++) {
for ($i=0; $i < count($end); $i++) {
if($end2[$i] == $arr1[$j]) {
$arr2[] = $end[$i];
}
}
}
$final_ecat_ids = $arr2;
}
}
if($_REQUEST['type'] == 'mid-category') {
if(!in_array($_REQUEST['id'],$mid)) {
header('location: index.php');
exit;
} else {
// Getting Title
for ($i=0; $i < count($mid); $i++) {
if($mid[$i] == $_REQUEST['id']) {
$title = $mid1[$i];
break;
}
}
$arr2 = array();
// Find out all ecat ids under this
for ($i=0; $i < count($end); $i++) {
if($end2[$i] == $_REQUEST['id']) {
$arr2[] = $end[$i];
}
}
$final_ecat_ids = $arr2;
}
}
if($_REQUEST['type'] == 'end-category') {
if(!in_array($_REQUEST['id'],$end)) {
header('location: index.php');
exit;
} else {
// Getting Title
for ($i=0; $i < count($end); $i++) {
if($end[$i] == $_REQUEST['id']) {
$title = $end1[$i];
break;
}
}
$final_ecat_ids = array($_REQUEST['id']);
}
}
}
}
?>
<div class="page-banner" style="background-image: url(assets/uploads/<?php echo $banner_product_category; ?>)">
<div class="inner">
<h1><?php echo LANG_VALUE_50; ?> <?php echo $title; ?></h1>
</div>
</div>
<div class="page">
<div class="container">
<div class="row">
<div class="col-md-3">
<?php require_once('sidebar-category.php'); ?>
</div>
<div class="col-md-9">
<h3><?php echo LANG_VALUE_51; ?> "<?php echo $title; ?>"</h3>
<div class="product product-cat">
<div class="row">
<?php
// Checking if any product is available or not
$prod_count = 0;
$statement = $pdo->prepare("SELECT * FROM tbl_product");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$prod_table_ecat_ids[] = $row['ecat_id'];
}
for($ii=0;$ii<count($final_ecat_ids);$ii++):
if(in_array($final_ecat_ids[$ii],$prod_table_ecat_ids)) {
$prod_count++;
}
endfor;
if($prod_count==0) {
echo '<div class="pl_15">'.LANG_VALUE_153.'</div>';
} else {
for($ii=0;$ii<count($final_ecat_ids);$ii++) {
$statement = $pdo->prepare("SELECT * FROM tbl_product WHERE ecat_id=? AND p_is_active=?");
$statement->execute(array($final_ecat_ids[$ii],1));
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
?>
<div class="col-md-4 item item-product-cat">
<div class="inner">
<div class="thumb">
<div class="photo" style="background-image:url(assets/uploads/<?php echo $row['p_featured_photo']; ?>);"></div>
<div class="overlay"></div>
</div>
<div class="text">
<h3><a href="product.php?id=<?php echo $row['p_id']; ?>"><?php echo $row['p_name']; ?></a></h3>
<h4>
<?php echo LANG_VALUE_1; ?><?php echo $row['p_current_price']; ?>
<?php if($row['p_old_price'] != ''): ?>
<del>
<?php echo LANG_VALUE_1; ?><?php echo $row['p_old_price']; ?>
</del>
<?php endif; ?>
</h4>
<div class="rating">
<?php
$t_rating = 0;
$statement1 = $pdo->prepare("SELECT * FROM tbl_rating WHERE p_id=?");
$statement1->execute(array($row['p_id']));
$tot_rating = $statement1->rowCount();
if($tot_rating == 0) {
$avg_rating = 0;
} else {
$result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
foreach ($result1 as $row1) {
$t_rating = $t_rating + $row1['rating'];
}
$avg_rating = $t_rating / $tot_rating;
}
?>
<?php
if($avg_rating == 0) {
echo '';
}
elseif($avg_rating == 1.5) {
echo '
<i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i>
<i class="fa fa-star-o"></i>
<i class="fa fa-star-o"></i>
<i class="fa fa-star-o"></i>
';
}
elseif($avg_rating == 2.5) {
echo '
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i>
<i class="fa fa-star-o"></i>
<i class="fa fa-star-o"></i>
';
}
elseif($avg_rating == 3.5) {
echo '
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i>
<i class="fa fa-star-o"></i>
';
}
elseif($avg_rating == 4.5) {
echo '
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star"></i>
<i class="fa fa-star-half-o"></i>
';
}
else {
for($i=1;$i<=5;$i++) {
?>
<?php if($i>$avg_rating): ?>
<i class="fa fa-star-o"></i>
<?php else: ?>
<i class="fa fa-star"></i>
<?php endif; ?>
<?php
}
}
?>
</div>
<?php if($row['p_qty'] == 0): ?>
<div class="out-of-stock">
<div class="inner">
Out Of Stock
</div>
</div>
<?php else: ?>
<p><a href="product.php?id=<?php echo $row['p_id']; ?>"><i class="fa fa-shopping-cart"></i> <?php echo LANG_VALUE_154; ?></a></p>
<?php endif; ?>
</div>
</div>
</div>
<?php
}
}
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<?php require_once('footer.php'); ?>