This repository was archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproduct.php
executable file
·257 lines (234 loc) · 8.44 KB
/
product.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
<?php
require_once('database.php');
require_once('server.php');
require_once('categoryfunction.php');
if(isset($_SESSION['customer']) && !empty($_SESSION['customer'])) {
$cid = $_SESSION['id'];
}
else {
header('location:index.php');
}
$catid = 0;
$begin = 0;
$offset = 9;
$searchtxt = "";
if(isset($_GET['categoryid']) && !empty($_GET['categoryid'])) {
$catid = $_GET['categoryid'];
}
$querystr = " and catid in ($catid";
if(isset($_GET['begin']) && !empty($_GET['begin'])) {
$begin = $_GET['begin'];
}
if(isset($_GET['search-product']) && !empty($_GET['search-product'])) {
$searchtxt = " and com.name like '%".$_GET['search-product']."%' ";
}
$catres = fetchCategoryChildren($catid);
foreach ($catres as $key=>$value) {
$querystr .= ", ".$value;
}
$querystr .= ") ";
$res = mysqli_query($db,"SELECT count(*) as count from commodities as com, categories as cat, vendors as v where v.id=com.vid and cat.id=com.catid $querystr $searchtxt");
$countresult=mysqli_fetch_assoc($res);
$count = $countresult['count'];
require_once('header.php');
include('errors.php');
?>
<!-- Title Page -->
<section class="bg-title-page p-t-50 p-b-40 flex-col-c-m" style="background-image: url(https://i.imgur.com/HVNZcxb.jpg);">
<h2 class="l-text2 bg-info rounded p-t-5 p-b-5 p-l-5 p-r-5 t-center">
Agriculture Commodities
</h2>
<p class="m-text13 bg-info rounded p-t-5 p-b-5 p-l-5 p-r-5 t-center">
All types of Agriculture Commodities Trade
</p>
</section>
<!-- Content page -->
<section class="bgwhite p-t-55 p-b-65">
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3 p-b-30">
<form class="search-product pos-relative bo4 of-hidden m-b-30" action="" method="GET">
<input type="hidden" name="categoryid" value="<?php echo $catid; ?>" />
<input class="s-text7 size6 p-l-23 p-r-50" type="text" name="search-product" placeholder="Search Products..." />
<button type="submit" value="searchcommodity" class="flex-c-m size5 ab-r-m color2 color0-hov trans-0-4">
<i class="fs-12 fa fa-search" aria-hidden="true"></i>
</button>
</form>
<div class="leftbar p-r-20 p-r-0-sm">
<!-- -->
<h4 class="m-text14 p-b-7">
Categories
</h4>
<p><a class="size6 p-t-5" href="product.php?categoryid=0">ALL</a></p>
<?php
$rescat = fetchCategoryTreeList();
foreach ($rescat as $key=>$r) {
echo $r;
}
?>
</div>
</div>
<?php
if($count<=0) {
?>
<div class="flex-sb-m flex-w p-b-35">
<h3>
No Commodities Available for the selected category
</h3>
</div>
<?php
}
else {
$res = mysqli_query($db,"SELECT vid,c.id,c.lat as lat1, c.lon as lon1, v.lat as lat2,v.lon as lon2 from vendors as v, commodities as com, customers as c where com.vid=v.id and c.id=$cid group by vid");
while($latlon = mysqli_fetch_assoc($res)) {
$distancearray[$latlon['vid']] = distance($latlon['lat1'],$latlon['lon1'],$latlon['lat2'],$latlon['lon2'],"K");
}
$vidstr = "ORDER BY FIELD(vid, '0'";
asort($distancearray);
foreach ($distancearray as $key => $value) {
$vidstr .= ", '".$key."'";
}
$vidstr .= ") asc,comname asc";
$res = mysqli_query($db,"SELECT com.id as comid, com.name as comname, avail, vid, price, catid, image_url, cat.name as catname, parentid, v.name as vname, lon, lat from commodities as com, categories as cat, vendors as v where v.id=com.vid and cat.id=com.catid $searchtxt $querystr $vidstr LIMIT $begin,$offset");
if(!$res)
array_push($errors,mysqli_error());
?>
<div class="col-sm-6 col-md-8 col-lg-9 p-b-25">
<div class="flex-sb-m flex-w p-b-35">
<span class="s-text7 p-t-5 p-b-5">
Default Sorting: Nearest Location
</span>
<span class="s-text8 p-t-5 p-b-5">
Showing <?php
echo $begin."-";
if(($begin+$offset)<=$count)
echo $begin+$offset;
else
echo $count;
echo " of ".$count;
?> results
</span>
</div>
<!-- 12? Product -->
<div class="row">
<?php
while($row=mysqli_fetch_assoc($res)) {
?>
<div class="col-sm-12 col-md-6 col-lg-4 p-b-50">
<!-- Block2 -->
<div class="block2">
<div class="block2-img wrap-pic-w of-hidden pos-relative">
<img class="featured-img" src="<?php echo $row['image_url']; ?>" alt="IMG-PRODUCT">
<div class="p-t-10 p-l-140 block2-overlay trans-0-4 text-white">
Available : <?php echo $row['avail']; ?>
<div class="w-size1">
<div class="block2-btn-addcart w-size1">
<!-- Button -->
<button class="addtocart flex-c-m size1 bg4 bo-rad-23 hov1 s-text1" id='addtocart_<?php echo $row['comid']; ?>' data-id='addtocart_<?php echo $row['comid']; ?>'>
Add to Cart
</button>
</div>
</div>
</div>
</div>
<div class="block2-txt p-t-5 p-b-5">
<a href="product-detail.php?commodityid=<?php echo $row['comid'];?>" class="block2-name dis-block s-text3 p-b-5">
<?php echo ucwords($row['comname']); ?>
</a>
<span class="p-r-5">
Rate: ₹ <span class="block2-price m-text6" ><?php echo $row['price']; ?></span>
</span>
<span class="p-r-5">
Distance: <span ><?php echo round($distancearray[$row['vid']],4); ?> km</span>
</span>
<div class="p-r-5">
Vendor:
<a href="profile.php?vendorid=<?php echo $row['vid']; ?>" class="m-text6 notranslate">
<?php echo $row['vname']; ?>
</a>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
<!-- Pagination -->
<div class="pagination flex-m flex-w p-t-26">
<?php
if($count/$offset>1) {
for($x=0;$x<$count/$offset;$x++) {
?>
<a href="product.php?categoryid=<?php echo $catid; ?>&begin=<?php echo $x*$offset; ?>" class="item-pagination flex-c-m trans-0-4 active-pagination"><?php echo $x+1; ?></a>
<?php
}
}
?>
</div>
</div>
<?php
}
?>
</div>
</div>
</section>
<!-- Back to top -->
<div class="btn-back-to-top bg0-hov" id="myBtn">
<span class="symbol-btn-back-to-top">
<i class="fa fa-angle-double-up" aria-hidden="true"></i>
</span>
</div>
<?php require_once('footer.php'); ?>
<!--===============================================================================================-->
<!-- Container Selection -->
<div id="dropDownSelect1"></div>
<div id="dropDownSelect2"></div>
<script type="text/javascript">
$(".selection-1").select2({
minimumResultsForSearch: 20,
dropdownParent: $('#dropDownSelect1')
});
$(".selection-2").select2({
minimumResultsForSearch: 20,
dropdownParent: $('#dropDownSelect2')
});
</script>
<!-- Set rating -->
<script type='text/javascript'>
$(document).ready(function() {
$(".addtocart").click(function() {
// Get element id by data-id attribute
var el_id = $(this).data("id")
// commodity was selected by a user
var split_id = el_id.split("_");
var comid = split_id[1]; // postid
var value = 1;
// AJAX Request
$.ajax({
url: 'addtocart_ajax.php',
type: 'post',
data: {comid:comid,quantity:value},
dataType: 'json',
success: function(data){
var status = data['status'];
var nameProduct = $(this).parent().parent().parent().find('.block2-name').html();
$(this).on('click', function(){
swal(nameProduct, "is added to cart !", "success");
});
if(!status)
agalert("Alert","Commodity already exists in the cart","yellow");
else if(status==-1)
swal("Error while adding Commodity to cart","failure");
else if(status==1) {
$(".cartcount").text(parseInt($(".cartcount").text()[0])+1);
swal("Successfully added Commodity to cart","success");
}
}
});
});
});
</script>
<!--===============================================================================================-->
</body>
</html>