/
placeorder.php
163 lines (161 loc) · 5.34 KB
/
placeorder.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
<!DOCTYPE html>
<html>
<head>
<?php include 'reqs.php';?>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link rel = "stylesheet" href = "cart.css">
<title>Grocery Store</title>
<script>
checklogin();
$.ajax({
type: "POST",
url: "data.php",
data: {
type: "addcnt",
},
cache: false,
success: function(data) {
obj = JSON.parse(data);
if(obj['cnt'] == 0)
{
alert("Please add address in account page before checking out");
window.location = "index.php";
}
}
});
$.ajax({
type: "POST",
url: "data.php",
data: {
type: "checkcartempty",
},
cache: false,
success: function(data) {
obj = JSON.parse(data);
if(obj['cnt'] == 0)
{
alert("Cart Is Empty");
window.location = "index.php";
}
}
});
function updateTotal()
{
$sum = 0;
$(".subtotal").each(function(idx){
$sum += parseFloat($(this).text().substring(1));
});
$('#total').html("<strong>Total ₹" + $sum + "</strong>");
}
</script>
</head>
<body>
<?php include 'navbar.php';?>
<div id="container">
<h1 align=middle>Confirm Order</h1>
<hr>
<div class="container">
<table id="cart" class="table table-hover table-condensed">
<thead>
<tr>
<th style="width:50%" align=middle>Product</th>
<th style="width:10%" align=middle>Price</th>
<th style="width:8%" align=middle>Quantity</th>
<th style="width:22%" class="text-center">Subtotal</th>
</tr>
</thead>
<tbody id="items">
</tbody>
<tfoot>
<tr>
<td><a href="index.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" id="total"></td>
<td><span class="btn btn-success btn-block" id="odbutton">Place Order <i class="fa fa-angle-right"></i></span></td>
</tr>
</tfoot>
</table>
</div>
<hr>
<h1 align=middle>Select Payment Method</h1>
<select class="form-control" id="sel1">
<option>Cash</option>
<option>Net Banking</option>
<option>Credit Card</option>
<option>Debit Card</option>
</select>
<br/>
<h1 align=middle>Select Address</h1>
<div class = "container-fluid" id="address">
</div>
<hr>
</div>
</body>
<script>
$('#odbutton').click(function(){
$x = $( "#sel1" ).find( "option:selected" ).text();
console.log($x);
$.ajax({
type: "POST",
url: "data.php",
data: {
type: "orderdone",
paymode: $x
},
cache: false,
success: function(data) {
console.log(data);
obj = JSON.parse(data);
if('err' in obj)
{
alert("Error in placing order, please refresh all items in your cart");
}
window.location = "index.php";
}
});
return true;
});
function setadd($a,$aid)
{
$.ajax({
type: "POST",
url: "data.php",
data: {
type: "setaddid",
aid: $aid
},
cache: false,
success: function(data) {
$.toaster('Address ' + $a + ' selected','Success','info');
}
});
}
$(document).ready(function(){
$.ajax({
type: "POST",
url: "data.php",
data: {
type: "vieworder"
},
dataType: "html",
cache: false,
success: function(data) {
$("#items").html(data);
updateTotal();
}
});
$.ajax({
type: "POST",
url: "data.php",
data: {
type: "seladdress"
},
dataType: "html",
cache: false,
success: function(data) {
$("#address").html(data);
$("#add1").click();
}
});
})
</script>