-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmycart.php
212 lines (203 loc) · 8.48 KB
/
mycart.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
<?php include 'header.php' ?>
<?php
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$user_id = $_SESSION['user'];
?>
<body>
<?php include 'navbar.php'; ?>
<div class="large-content" id="mycart">
<div class="overlay">
<h1 class="strip-head"><img class="head-icon" src="images/icons/noticart.png"><br>Your Cart<br><img class="head-hr" src="images/icons/hr2.png"></h1>
<div id="cartdiv">
<?php
$query1 = mysqli_query($bd,"SELECT * FROM cart INNER JOIN menu ON c_mid=m_id WHERE c_uid='$user_id'");
if(mysqli_num_rows($query1)>0) {
?>
<form id="cart-form" method="post" onsubmit="buycart()">
<table class="menutable">
<tr class="t-head1">
<th>Select</th>
<th>Menu Item</th>
<th>Qty</th>
<th>Price (Rs)</th>
</tr>
<?php
while ($row1 = mysqli_fetch_array($query1))
{
?>
<tr id="<?php echo $row1['c_id']; ?>" class="c_row">
<td class="m_id" id="<?php echo $row1['m_id']; ?>">
<input type="checkbox" onclick="removefromcart(this)" name="<?php echo $row1['c_id']; ?>"
value="<?php echo $row1['m_id']; ?>" checked></td>
<td>
<h4><?php echo ucwords($row1['m_name']); ?></h4>
<p><?php echo ucfirst($row1['m_desc']); ?></p>
</td>
<td><input class="cmqty" name="<?php echo $row1['m_price']; ?>" type="number" min="1"
max="50" value="1" oninput="changeprice(this)"></td>
<td class="cmqp"><?php echo $row1['m_price']; ?></td>
</tr>
<?php
}
?>
<tr id="cartotle">
<td colspan="4"><h3>Total : Rs.<span id="rs">200</span></h3></td>
</tr>
<tr class="ctpay">
<td colspan="4">
<center>
<div class="col-sm-7">
<h3>Deliver to</h3>
<div id="chaddr">
<div>
<input type="radio" name="adr" value="<?php echo $_SESSION['addr']; ?>"
checked onchange="addrchange(this)"> Your home address<br>
<input id="tro" type="radio" name="adr" value=""
onchange="addrchange(this)"> Another address<br>
</div>
<div>
<textarea id="dcaddr" readonly placeholder="Enter New Address"><?php echo $_SESSION['addr']; ?></textarea><br><br>
<select class="seltown" id="cart_town" disabled>
<?php
$twq = mysqli_query($bd,'SELECT * FROM town ORDER BY t_id ASC');
while($twr = mysqli_fetch_array($twq))
{?>
<option value="<?php echo $twr['t_id']; ?>" <?php if($twr['t_id']==$_SESSION['town']) echo 'selected'; ?>>
<?php echo ucwords($twr['t_name']) ?>
</option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="col-sm-5">
<h3>Payment Options</h3>
<input type="radio" name="cartpay" value="op" checked> Online Payment<br>
<input type="radio" name="cartpay" value="cod"> Cash On Delivery<br><br>
</div>
</center>
</td>
</tr>
<tr id="ftbuy">
<td colspan="4">
<center>
<button type="submit" name="btn_cart" class="submit-btn">Buy Cart</button>
</center>
</td>
</tr>
</table>
</form>
<?php
}
else
{?>
<center>
<div class="emptyc">
<h2>Your cart is empty!</h2><br>
<button type="button" class="submit-btn" onclick="location.href='menu.php';">Add items to cart</button>
</div>
</center>
<?php
}?>
</div>
</div>
</div>
<script>
function removefromcart(cartrow)
{
var cid = cartrow.name;
console.log(cid);
if( !$(cartrow).prop('checked') )
{
$.ajax({
type: 'POST',
url: 'phpfunctions.php',
data: {
'crmid': cid
},
success: function(rem) {
if(rem=="removed")
{
$(cartrow).parent().parent().remove();
changetotal();
}
}
});
}
}
function changetotal()
{
var total=0;
$('.cmqp').each(function() {
total += parseInt($(this).text());
})
$('#rs').text(total);
if(total==0)
{
$('#cartdiv').load(' #cartdiv');
}
}
changetotal();
function changeprice(obj)
{
var singlep = parseInt(obj.name);
var qty = parseInt(obj.value);
var price = singlep*qty;
$(obj).parent().next().text(price);
changetotal();
}
function addrchange(rb) {
if( $(rb).prop('checked') )
{
$('#dcaddr').val(rb.value);
if(rb.id=="tro") {
$('#dcaddr').removeAttr('readonly');
$('#cart_town').removeAttr('disabled');
}
else {
$('#dcaddr').attr('readonly', 'true');
$('#cart_town').attr('disabled','true');
}
}
}
var ciqty = [];
var cipri = [];
function buycart() {
ciqty = $('.cmqty').map(function(){
return $(this).val()
}).get();
var jscqt = JSON.stringify(ciqty);
cipri = $('.cmqp').map(function(){
return $(this).text()
}).get();
var jscpr = JSON.stringify(cipri);
console.log(cipri);
var total = $('#rs').text();
var addr = $('#dcaddr').val();
var ct = $('#cart_town').val();
var pay = $('input:radio[name="cartpay"]:checked').val();
$.ajax({
type: 'POST',
url: 'phpfunctions.php',
data: {
'ciqty': jscqt,
'cipri': jscpr,
'ctotal': total,
'addr': addr,
'ctw': ct,
'cpay': pay
},
success: function(msg) {
window.location.href='myorders.php';
alert(msg);
}
});
}
</script>
<?php include 'footer.php'; ?>
</body>