-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.php
180 lines (160 loc) · 7.3 KB
/
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
<?php include 'check.php';
$category_id = $query->validate($_GET['category']);
$product_id = $query->select('products', 'id', 'where category_id = ' . $category_id);
if (!is_numeric($category_id) or !$product_id) {
header("Location: ./");
exit;
}
$name = $query->select('categories', 'category_name', "where id = '$category_id'")[0]['category_name'];
?>
<!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-9 col-md-7">
<div class="product__discount">
<div class="section-title product__discount__title">
<h2><?php echo $name ?> </h2>
</div>
</div>
</div>
</div>
<div class="row">
<?php
$products = $query->select('products', '*', "WHERE category_id = '$category_id'");
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-3 col-md-4 col-sm-6">
<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>
</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>