-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart_list.php
More file actions
155 lines (149 loc) · 5.57 KB
/
Copy pathcart_list.php
File metadata and controls
155 lines (149 loc) · 5.57 KB
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
<!-- Masthead-->
<header class="masthead">
<div class="container h-100">
<div class="row h-100 align-items-center justify-content-center text-center">
<div class="col-lg-10 align-self-center mb-4 page-title">
<h1 class="text-white">Shopping Cart</h1>
<hr class="divider my-4 bg-dark" />
</div>
</div>
</div>
</header>
<section class="page-section" id="menu">
<div class="container">
<div class="row">
<div class="col-lg-8">
<div class="sticky">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-8"><b>Items</b></div>
<div class="col-md-4 text-right"><b>Total</b></div>
</div>
</div>
</div>
</div>
<?php
if(isset($_SESSION['login_user_id'])){
$data = "where c.user_id = '".$_SESSION['login_user_id']."' ";
}else{
$ip = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
$data = "where c.client_ip = '".$ip."' ";
}
$total = 0;
$get = $conn->query("SELECT *,c.id as cid FROM cart c inner join product_list p on p.id = c.product_id ".$data);
while($row= $get->fetch_assoc()):
$total += ($row['qty'] * $row['price']);
?>
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-4 d-flex align-items-center" style="text-align: -webkit-center">
<div class="col-auto">
<a href="admin/ajax.php?action=delete_cart&id=<?php echo $row['cid'] ?>" class="rem_cart btn btn-sm btn-outline-danger" data-id="<?php echo $row['cid'] ?>"><i class="fa fa-trash"></i></a>
</div>
<div class="col-auto flex-shrink-1 flex-grow-1 text-center">
<img src="assets/img/<?php echo $row['img_path'] ?>" alt="">
</div>
</div>
<div class="col-md-4">
<p><b><large><?php echo $row['name'] ?></large></b></p>
<p class='truncate'> <b><small>Desc :<?php echo $row['description'] ?></small></b></p>
<p> <b><small>Unit Price :<?php echo number_format($row['price'],2) ?></small></b></p>
<p><small>QTY :</small></p>
<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary qty-minus" type="button" data-id="<?php echo $row['cid'] ?>"><span class="fa fa-minus"></button>
</div>
<input type="number" readonly value="<?php echo $row['qty'] ?>" min = 1 class="form-control text-center" name="qty" >
<div class="input-group-prepend">
<button class="btn btn-outline-secondary qty-plus" type="button" id="" data-id="<?php echo $row['cid'] ?>"><span class="fa fa-plus"></span></button>
</div>
</div>
</div>
<div class="col-md-4 text-right">
<b><large><?php echo number_format($row['qty'] * $row['price'],2) ?></large></b>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="col-md-4">
<div class="sticky">
<div class="card">
<div class="card-body">
<p><large>Total Amount</large></p>
<hr>
<p class="text-right"><b><?php echo number_format($total,2) ?></b></p>
<hr>
<div class="text-center">
<button class="btn btn-block btn-outline-dark" type="button" id="checkout">Proceed to Checkout</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<style>
.card p {
margin: unset
}
.card img{
max-width: calc(100%);
max-height: calc(59%);
}
div.sticky {
position: -webkit-sticky; /* Safari */
position: sticky;
top: 4.7em;
z-index: 10;
background: white
}
.rem_cart{
position: absolute;
left: 0;
}
</style>
<script>
$('.view_prod').click(function(){
uni_modal_right('Product','view_prod.php?id='+$(this).attr('data-id'))
})
$('.qty-minus').click(function(){
var qty = $(this).parent().siblings('input[name="qty"]').val();
update_qty(parseInt(qty) -1,$(this).attr('data-id'))
if(qty == 1){
return false;
}else{
$(this).parent().siblings('input[name="qty"]').val(parseInt(qty) -1);
}
})
$('.qty-plus').click(function(){
var qty = $(this).parent().siblings('input[name="qty"]').val();
$(this).parent().siblings('input[name="qty"]').val(parseInt(qty) +1);
update_qty(parseInt(qty) +1,$(this).attr('data-id'))
})
function update_qty(qty,id){
start_load()
$.ajax({
url:'admin/ajax.php?action=update_cart_qty',
method:"POST",
data:{id:id,qty},
success:function(resp){
if(resp == 1){
load_cart()
end_load()
}
}
})
}
$('#checkout').click(function(){
if('<?php echo isset($_SESSION['login_user_id']) ?>' == 1){
location.replace("index.php?page=checkout")
}else{
uni_modal("Checkout","login.php?page=checkout")
}
})
</script>