-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
288 lines (258 loc) · 14.2 KB
/
index.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
<?php include 'check.php'; ?>
<!DOCTYPE html>
<html lang="eng">
<head>
<meta charset="UTF-8">
<meta name="description" content="Ogani Template">
<meta name="keywords" content="Ogani, unica, creative, html">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" href="./favicon.ico">
<title>iMarket</title>
<!-- Google Font -->
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@200;300;400;600;900&display=swap" rel="stylesheet">
<!-- Css Styles -->
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="css/font-awesome.min.css" type="text/css">
<link rel="stylesheet" href="css/elegant-icons.css" type="text/css">
<link rel="stylesheet" href="css/nice-select.css" type="text/css">
<link rel="stylesheet" href="css/jquery-ui.min.css" type="text/css">
<link rel="stylesheet" href="css/owl.carousel.min.css" type="text/css">
<link rel="stylesheet" href="css/slicknav.min.css" type="text/css">
<link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
</head>
<body>
<?php include 'header.php'; ?>
<!-- Product Section Begin -->
<section class="product spad">
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-5">
<div class="sidebar">
<div class="sidebar__item">
<h4>Categoriya</h4>
<ul>
<?php
$categories = $query->select('categories', '*');
foreach ($categories as $category): ?>
<li><a
href="category.php?category=<?php echo $category['id'] ?>"><?php echo $category['category_name']; ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="sidebar__item">
<h4>Price</h4>
<?php
$result = $query->executeQuery("SELECT MIN(price_current) AS min_price, MAX(price_current) AS max_price FROM products");
$row = $result->fetch_assoc();
$min_price = $row['min_price'];
$max_price = $row['max_price'];
?>
<div class="price-range-wrap">
<div class="price-range ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content"
data-min="<?php echo $min_price; ?>" data-max="<?php echo $max_price; ?>">
<div class="ui-slider-range ui-corner-all ui-widget-header"></div>
<span tabindex="0" class="ui-slider-handle ui-corner-all ui-state-default"></span>
<span tabindex="0" class="ui-slider-handle ui-corner-all ui-state-default"></span>
</div>
<div class="range-slider">
<div class="price-input">
<input type="text" id="minamount" value="<?php echo $min_price; ?>">
<input type="text" id="maxamount" value="<?php echo $max_price; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-9 col-md-7">
<?php
$categories = $query->select('categories', '*', 'LIMIT 3');
foreach ($categories as $category): ?>
<div class="product__discount">
<div class="section-title product__discount__title">
<h2><?php echo $category['category_name']; ?></h2>
</div>
<div class="row">
<div class="product__discount__slider owl-carousel">
<?php
$products = $query->select('products', '*', 'WHERE category_id = ' . $category['id'] . ' LIMIT 6');
foreach ($products as $product):
$product_name = $product['name'];
$category_name = $category['category_name'];;
$price_current = $product['price_current'];
$price_old = $product['price_old'];
$product_id = $product['id'];
$image = $query->select('product_images', 'image_url', "where product_id = '$product_id'")[0]['image_url'];
?>
<div class="col-lg-4">
<div class="product__discount__item">
<div class="product__discount__item__pic set-bg"
data-setbg="images/products/<?php echo $image ?>">
<ul class="product__item__pic__hover">
<li><a onclick="addToWishlist(<?php echo $product_id; ?>)"><i
class="fa fa-heart"></i></a></li>
<li><a onclick="openProductDetails(<?php echo $product_id; ?>)"><i
class="fa fa-retweet"></i></a></li>
<li><a onclick="addToCart(<?php echo $product_id; ?>)"><i
class="fa fa-shopping-cart"></i></a></li>
</ul>
</div>
<div class="product__discount__item__text">
<span><?php echo $category_name; ?></span>
<h5><a
onclick="openProductDetails(<?php echo $product_id; ?>)"><?php echo $product_name; ?></a>
</h5>
<div class="product__item__price">$<?php echo $price_current; ?>
<span>$<?php echo $price_old; ?></span>
</div>
</div>
</div>
</div>
<?php endforeach ?>
</div>
</div>
</div>
<?php endforeach; ?>
<div class="filter__item">
<div class="row">
<div class="col-lg-4 col-md-5">
<div class="filter__sort">
<span>Sort By</span>
<select>
<option value="0">Default</option>
<option value="0">Default</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4">
<div class="filter__found">
<h6><span>16</span> Products found</h6>
</div>
</div>
<div class="col-lg-4 col-md-3">
<div class="filter__option">
<span class="icon_grid-2x2"></span>
<span class="icon_ul"></span>
</div>
</div>
</div>
</div>
<div class="row">
<?php
$products = $query->select('products', '*', "LIMIT 15");
foreach ($products as $product):
$product_name = $product['name'];
$category_name = $query->select('categories', 'category_name', 'WHERE id=' . $product['category_id'])[0]['category_name'];
$price_current = $product['price_current'];
$price_old = $product['price_old'];
$product_id = $product['id'];
$image = $query->select('product_images', 'image_url', "where product_id = '$product_id'")[0]['image_url'];
?>
<div class="col-lg-4">
<div class="product__discount__item">
<div class="product__discount__item__pic set-bg"
data-setbg="images/products/<?php echo $image ?>">
<ul class="product__item__pic__hover">
<li><a onclick="addToWishlist(<?php echo $product_id; ?>)"><i
class="fa fa-heart"></i></a></li>
<li><a onclick="openProductDetails(<?php echo $product_id; ?>)"><i
class="fa fa-retweet"></i></a></li>
<li><a onclick="addToCart(<?php echo $product_id; ?>)"><i
class="fa fa-shopping-cart"></i></a></li>
</ul>
</div>
<div class="product__discount__item__text">
<span><?php echo $category_name; ?></span>
<h5><a
onclick="openProductDetails(<?php echo $product_id; ?>)"><?php echo $product_name; ?></a>
</h5>
<div class="product__item__price">$<?php echo $price_current; ?>
<span>$<?php echo $price_old; ?></span>
</div>
</div>
</div>
</div>
<?php endforeach ?>
</div>
</div>
</div>
</div>
</section>
<!-- Product Section End -->
<!-- Footer Section Begin -->
<?php include 'footer.php'; ?>
<!-- Footer Section End -->
<!-- Js Plugins -->
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.nice-select.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/jquery.slicknav.js"></script>
<script src="js/mixitup.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/main.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
$(function() {
var min_price = <?php echo $min_price; ?>;
var max_price = <?php echo $max_price; ?>;
$(".price-range").slider({
range: true,
min: min_price,
max: max_price,
values: [min_price, max_price],
slide: function(event, ui) {
$("#minamount").val(ui.values[0]);
$("#maxamount").val(ui.values[1]);
}
});
$("#minamount").val($(".price-range").slider("values", 0));
$("#maxamount").val($(".price-range").slider("values", 1));
});
</script>
<script>
function addToCart(productId) {
var xhr = new XMLHttpRequest();
var url = 'add_to_cart.php?product_id=' + productId;
xhr.open('GET', url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
Swal.fire({
icon: 'success',
title: 'Mahsulot savatchaga qo\'shildi!',
showConfirmButton: false,
timer: 1500
}).then(() => {
window.location.reload();
});
}
};
}
function addToWishlist(productId) {
var xhr = new XMLHttpRequest();
var url = 'add_to_wishlist.php?product_id=' + productId;
xhr.open('GET', url, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
Swal.fire({
icon: 'success',
title: 'Mahsulot izohga qo\'shildi!',
showConfirmButton: false,
timer: 1500
}).then(() => {
window.location.reload();
});
}
};
}
function openProductDetails(productId) {
window.location.href = 'shop-details.php?product_id=' + productId;
}
</script>
</body>
</html>