-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.php
541 lines (443 loc) · 18.1 KB
/
action.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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
<?php
session_start();
$ip_add = getenv("REMOTE_ADDR");
include "db.php";
if(isset($_POST["category"])){
$category_query = "SELECT * FROM categories";
$run_query = mysqli_query($con,$category_query) or die(mysqli_error($con));
echo
<div class='aside'>
<h3 class='aside-title'>Categories</h3>
<div class='btn-group-vertical'>
";
if(mysqli_num_rows($run_query) > 0){
$i=1;
while($row = mysqli_fetch_array($run_query)){
$cid = $row["cat_id"];
$cat_name = $row["cat_title"];
$sql = "SELECT COUNT(*) AS count_items FROM products WHERE product_cat=$i";
$query = mysqli_query($con,$sql);
$row = mysqli_fetch_array($query);
$count=$row["count_items"];
$i++;
echo
<div type='button' class='btn navbar-btn category' cid='$cid'>
<a href='#'>
<span ></span>
$cat_name
<small class='qty'>($count)</small>
</a>
</div>
";
}
echo "</div>";
}
}
if(isset($_POST["brand"])){
$brand_query = "SELECT * FROM brands";
$run_query = mysqli_query($con,$brand_query);
echo
<div class='aside'>
<h3 class='aside-title'>Brand</h3>
<div class='btn-group-vertical'>
";
if(mysqli_num_rows($run_query) > 0){
$i=1;
while($row = mysqli_fetch_array($run_query)){
$bid = $row["brand_id"];
$brand_name = $row["brand_title"];
$sql = "SELECT COUNT(*) AS count_items FROM products WHERE product_brand=$i";
$query = mysqli_query($con,$sql);
$row = mysqli_fetch_array($query);
$count=$row["count_items"];
$i++;
echo
<div type='button' class='btn navbar-btn selectBrand' bid='$bid'>
<a href='#'>
<span ></span>
$brand_name
<small >($count)</small>
</a>
</div>
";
}
echo "</div>";
}
}
if(isset($_POST["page"])){
$sql = "SELECT * FROM products";
$run_query = mysqli_query($con,$sql);
$count = mysqli_num_rows($run_query);
$pageno = ceil($count/9);
for($i=1;$i<=$pageno;$i++){
echo
<li><a href='#product-row' page='$i' id='page' class='active'>$i</a></li>
";
}
}
if(isset($_POST["getProduct"])){
$limit = 9;
if(isset($_POST["setPage"])){
$pageno = $_POST["pageNumber"];
$start = ($pageno * $limit) - $limit;
}else{
$start = 0;
}
$product_query = "SELECT * FROM products,categories WHERE product_cat=cat_id LIMIT $start,$limit";
$run_query = mysqli_query($con,$product_query);
if(mysqli_num_rows($run_query) > 0){
while($row = mysqli_fetch_array($run_query)){
$pro_id = $row['product_id'];
$pro_cat = $row['product_cat'];
$pro_brand = $row['product_brand'];
$pro_title = $row['product_title'];
$pro_price = $row['product_price'];
$pro_image = $row['product_image'];
$cat_name = $row["cat_title"];
echo
<div class='col-md-4 col-xs-6' >
<a href='product.php?p=$pro_id'><div class='product'>
<div class='product-img'>
<img src='product_images/$pro_image' style='max-height: 170px;' alt=''>
<div class='product-label'>
<span class='sale'>-30%</span>
<span class='new'>NEW</span>
</div>
</div></a>
<div class='product-body'>
<p class='product-category'>$cat_name</p>
<h3 class='product-name header-cart-item-name'><a href='product.php?p=$pro_id'>$pro_title</a></h3>
<h4 class='product-price header-cart-item-info'>$pro_price<del class='product-old-price'>$990.00</del></h4>
<div class='product-rating'>
<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'></i>
</div>
<div class='product-btns'>
<button class='add-to-wishlist'><i class='fa fa-heart-o'></i><span class='tooltipp'>add to wishlist</span></button>
<button class='add-to-compare'><i class='fa fa-exchange'></i><span class='tooltipp'>add to compare</span></button>
<button class='quick-view'><i class='fa fa-eye'></i><span class='tooltipp'>quick view</span></button>
</div>
</div>
<div class='add-to-cart'>
<button pid='$pro_id' id='product' class='add-to-cart-btn block2-btn-towishlist' href='#'><i class='fa fa-shopping-cart'></i> add to cart</button>
</div>
</div>
</div>
";
}
}
}
if(isset($_POST["get_seleted_Category"]) || isset($_POST["selectBrand"]) || isset($_POST["search"])){
if(isset($_POST["get_seleted_Category"])){
$id = $_POST["cat_id"];
$sql = "SELECT * FROM products,categories WHERE product_cat = '$id' AND product_cat=cat_id";
}else if(isset($_POST["selectBrand"])){
$id = $_POST["brand_id"];
$sql = "SELECT * FROM products,categories WHERE product_brand = '$id' AND product_cat=cat_id";
}else {
$keyword = $_POST["keyword"];
header('Location:store.php');
$sql = "SELECT * FROM products,categories WHERE product_cat=cat_id AND product_keywords LIKE '%$keyword%'";
}
$run_query = mysqli_query($con,$sql);
while($row=mysqli_fetch_array($run_query)){
$pro_id = $row['product_id'];
$pro_cat = $row['product_cat'];
$pro_brand = $row['product_brand'];
$pro_title = $row['product_title'];
$pro_price = $row['product_price'];
$pro_image = $row['product_image'];
$cat_name = $row["cat_title"];
echo
<div class='col-md-4 col-xs-6'>
<a href='product.php?p=$pro_id'><div class='product'>
<div class='product-img'>
<img src='product_images/$pro_image' style='max-height: 170px;' alt=''>
<div class='product-label'>
<span class='sale'>-30%</span>
<span class='new'>NEW</span>
</div>
</div></a>
<div class='product-body'>
<p class='product-category'>$cat_name</p>
<h3 class='product-name header-cart-item-name'><a href='product.php?p=$pro_id'>$pro_title</a></h3>
<h4 class='product-price header-cart-item-info'>$pro_price<del class='product-old-price'>$990.00</del></h4>
<div class='product-rating'>
<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'></i>
</div>
<div class='product-btns'>
<button class='add-to-wishlist' tabindex='0'><i class='fa fa-heart-o'></i><span class='tooltipp'>add to wishlist</span></button>
<button class='add-to-compare'><i class='fa fa-exchange'></i><span class='tooltipp'>add to compare</span></button>
<button class='quick-view' ><i class='fa fa-eye'></i><span class='tooltipp'>quick view</span></button>
</div>
</div>
<div class='add-to-cart'>
<button pid='$pro_id' id='product' href='#' tabindex='0' class='add-to-cart-btn'><i class='fa fa-shopping-cart'></i> add to cart</button>
</div>
</div>
</div>
";
}
}
if(isset($_POST["addToCart"])){
$p_id = $_POST["proId"];
if(isset($_SESSION["uid"])){
$user_id = $_SESSION["uid"];
$sql = "SELECT * FROM cart WHERE p_id = '$p_id' AND user_id = '$user_id'";
$run_query = mysqli_query($con,$sql);
$count = mysqli_num_rows($run_query);
if($count > 0){
echo
<div class='alert alert-warning'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<b>Product is already added into the cart Continue Shopping..!</b>
</div>
";//not in video
} else {
$sql = "INSERT INTO `cart`
(`p_id`, `ip_add`, `user_id`, `qty`)
VALUES ('$p_id','$ip_add','$user_id','1')";
if(mysqli_query($con,$sql)){
echo
<div class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<b>Product is Added..!</b>
</div>
";
}
}
}else{
$sql = "SELECT id FROM cart WHERE ip_add = '$ip_add' AND p_id = '$p_id' AND user_id = -1";
$query = mysqli_query($con,$sql);
if (mysqli_num_rows($query) > 0) {
echo
<div class='alert alert-warning'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<b>Product is already added into the cart Continue Shopping..!</b>
</div>";
exit();
}
$sql = "INSERT INTO `cart`
(`p_id`, `ip_add`, `user_id`, `qty`)
VALUES ('$p_id','$ip_add','-1','1')";
if (mysqli_query($con,$sql)) {
echo
<div class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<b>Your product is Added Successfully..!</b>
</div>
";
exit();
}
}
}
//Count User cart item
if (isset($_POST["count_item"])) {
//When user is logged in then we will count number of item in cart by using user session id
if (isset($_SESSION["uid"])) {
$sql = "SELECT COUNT(*) AS count_item FROM cart WHERE user_id = $_SESSION[uid]";
}else{
//When user is not logged in then we will count number of item in cart by using users unique ip address
$sql = "SELECT COUNT(*) AS count_item FROM cart WHERE ip_add = '$ip_add' AND user_id < 0";
}
$query = mysqli_query($con,$sql);
$row = mysqli_fetch_array($query);
echo $row["count_item"];
exit();
}
//Count User cart item
//Get Cart Item From Database to Dropdown menu
if (isset($_POST["Common"])) {
if (isset($_SESSION["uid"])) {
//When user is logged in this query will execute
$sql = "SELECT a.product_id,a.product_title,a.product_price,a.product_image,b.id,b.qty FROM products a,cart b WHERE a.product_id=b.p_id AND b.user_id='$_SESSION[uid]'";
}else{
//When user is not logged in this query will execute
$sql = "SELECT a.product_id,a.product_title,a.product_price,a.product_image,b.id,b.qty FROM products a,cart b WHERE a.product_id=b.p_id AND b.ip_add='$ip_add' AND b.user_id < 0";
}
$query = mysqli_query($con,$sql);
if (isset($_POST["getCartItem"])) {
//display cart item in dropdown menu
if (mysqli_num_rows($query) > 0) {
$n=0;
$total_price=0;
while ($row=mysqli_fetch_array($query)) {
$n++;
$product_id = $row["product_id"];
$product_title = $row["product_title"];
$product_price = $row["product_price"];
$product_image = $row["product_image"];
$cart_item_id = $row["id"];
$qty = $row["qty"];
$total_price=$total_price+$product_price;
echo
<div class="product-widget">
<div class="product-img">
<img src="product_images/'.$product_image.'" alt="">
</div>
<div class="product-body">
<h3 class="product-name"><a href="#">'.$product_title.'</a></h3>
<h4 class="product-price"><span class="qty">'.$n.'</span>$'.$product_price.'</h4>
</div>
</div>'
;
}
echo '<div class="cart-summary">
<small class="qty">'.$n.' Item(s) selected</small>
<h5>$'.$total_price.'</h5>
</div>'
?>
<?php
exit();
}
}
if (isset($_POST["checkOutDetails"])) {
if (mysqli_num_rows($query) > 0) {
//display user cart item with "Ready to checkout" button if user is not login
echo '<div class="main ">
<div class="table-responsive">
<form method="post" action="login_form.php">
<table id="cart" class="table table-hover table-condensed" id="">
<thead>
<tr>
<th style="width:50%">Product</th>
<th style="width:10%">Price</th>
<th style="width:8%">Quantity</th>
<th style="width:7%" class="text-center">Subtotal</th>
<th style="width:10%"></th>
</tr>
</thead>
<tbody>
';
$n=0;
while ($row=mysqli_fetch_array($query)) {
$n++;
$product_id = $row["product_id"];
$product_title = $row["product_title"];
$product_price = $row["product_price"];
$product_image = $row["product_image"];
$cart_item_id = $row["id"];
$qty = $row["qty"];
echo
<tr>
<td data-th="Product" >
<div class="row">
<div class="col-sm-4 "><img src="product_images/'.$product_image.'" style="height: 70px;width:75px;"/>
<h4 class="nomargin product-name header-cart-item-name"><a href="product.php?p='.$product_id.'">'.$product_title.'</a></h4>
</div>
<div class="col-sm-6">
<div style="max-width=50px;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
</div>
</div>
</div>
</td>
<input type="hidden" name="product_id[]" value="'.$product_id.'"/>
<input type="hidden" name="" value="'.$cart_item_id.'"/>
<td data-th="Price"><input type="text" class="form-control price" value="'.$product_price.'" readonly="readonly"></td>
<td data-th="Quantity">
<input type="text" class="form-control qty" value="'.$qty.'" >
</td>
<td data-th="Subtotal" class="text-center"><input type="text" class="form-control total" value="'.$product_price.'" readonly="readonly"></td>
<td class="actions" data-th="">
<div class="btn-group">
<a href="#" class="btn btn-info btn-sm update" update_id="'.$product_id.'"><i class="fa fa-refresh"></i></a>
<a href="#" class="btn btn-danger btn-sm remove" remove_id="'.$product_id.'"><i class="fa fa-trash-o"></i></a>
</div>
</td>
</tr>
';
}
echo '</tbody>
<tfoot>
<tr>
<td><a href="store.php" class="btn btn-warning"><i class="fa fa-angle-left"></i> Continue Shopping</a></td>
<td colspan="2" class="hidden-xs"></td>
<td class="hidden-xs text-center"><b class="net_total" ></b></td>
<div id="issessionset"></div>
<td>
';
if (!isset($_SESSION["uid"])) {
echo
<a href="" data-toggle="modal" data-target="#Modal_register" class="btn btn-success">Ready to Checkout</a></td>
</tr>
</tfoot>
</table></div></div>';
}else if(isset($_SESSION["uid"])){
//Paypal checkout form
echo
</form>
<form action="checkout.php" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="shoppingcart@puneeth.com">
<input type="hidden" name="upload" value="1">';
$x=0;
$sql = "SELECT a.product_id,a.product_title,a.product_price,a.product_image,b.id,b.qty FROM products a,cart b WHERE a.product_id=b.p_id AND b.user_id='$_SESSION[uid]'";
$query = mysqli_query($con,$sql);
while($row=mysqli_fetch_array($query)){
$x++;
echo
'<input type="hidden" name="total_count" value="'.$x.'">
<input type="hidden" name="item_name_'.$x.'" value="'.$row["product_title"].'">
<input type="hidden" name="item_number_'.$x.'" value="'.$x.'">
<input type="hidden" name="amount_'.$x.'" value="'.$row["product_price"].'">
<input type="hidden" name="quantity_'.$x.'" value="'.$row["qty"].'">';
}
echo
'<input type="hidden" name="return" value="http://localhost/myfiles/public_html/payment_success.php"/>
<input type="hidden" name="notify_url" value="http://localhost/myfiles/public_html/payment_success.php">
<input type="hidden" name="cancel_return" value="http://localhost/myfiles/public_html/cancel.php"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="custom" value="'.$_SESSION["uid"].'"/>
<input type="submit" id="submit" name="login_user_with_product" name="submit" class="btn btn-success" value="Ready to Checkout">
</form></td>
</tr>
</tfoot>
</table></div></div>
';
}
}
}
}
//Remove Item From cart
if (isset($_POST["removeItemFromCart"])) {
$remove_id = $_POST["rid"];
if (isset($_SESSION["uid"])) {
$sql = "DELETE FROM cart WHERE p_id = '$remove_id' AND user_id = '$_SESSION[uid]'";
}else{
$sql = "DELETE FROM cart WHERE p_id = '$remove_id' AND ip_add = '$ip_add'";
}
if(mysqli_query($con,$sql)){
echo "<div class='alert alert-danger'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<b>Product is removed from cart</b>
</div>";
exit();
}
}
//Update Item From cart
if (isset($_POST["updateCartItem"])) {
$update_id = $_POST["update_id"];
$qty = $_POST["qty"];
if (isset($_SESSION["uid"])) {
$sql = "UPDATE cart SET qty='$qty' WHERE p_id = '$update_id' AND user_id = '$_SESSION[uid]'";
}else{
$sql = "UPDATE cart SET qty='$qty' WHERE p_id = '$update_id' AND ip_add = '$ip_add'";
}
if(mysqli_query($con,$sql)){
echo "<div class='alert alert-info'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<b>Product is updated</b>
</div>";
exit();
}
}
?>