-
Notifications
You must be signed in to change notification settings - Fork 1
/
viewCart.php
184 lines (179 loc) · 10.6 KB
/
viewCart.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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<title>Cart</title>
<link rel = "icon" href ="img/logo.jpg" type = "image/x-icon">
<style>
#cont{
min-height : 626px;
}
</style>
</head>
<body>
<?php include 'partials/_dbconnect.php';?>
<?php require 'partials/_nav.php' ?>
<?php
if($loggedin){
?>
<div class="container" id="cont">
<div class="row">
<div class="alert alert-info mb-0" style="width: -webkit-fill-available;">
<strong>Info!</strong> online payment are currently disabled so please choose cash on delivery.
</div>
<div class="col-lg-12 text-center border rounded bg-light my-3">
<h1>My Cart</h1>
</div>
<div class="col-lg-8">
<div class="card wish-list mb-3">
<table class="table text-center">
<thead class="thead-light">
<tr>
<th scope="col">No.</th>
<th scope="col">Item Name</th>
<th scope="col">Item Price</th>
<th scope="col">Quantity</th>
<th scope="col">Total Price</th>
<th scope="col">
<form action="partials/_manageCart.php" method="POST">
<button name="removeAllItem" class="btn btn-sm btn-outline-danger">Remove All</button>
<input type="hidden" name="userId" value="<?php $userId = $_SESSION['userId']; echo $userId ?>">
</form>
</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM `viewcart` WHERE `userId`= $userId";
$result = mysqli_query($conn, $sql);
$counter = 0;
$totalPrice = 0;
while($row = mysqli_fetch_assoc($result)){
$pizzaId = $row['pizzaId'];
$Quantity = $row['itemQuantity'];
$mysql = "SELECT * FROM `pizza` WHERE pizzaId = $pizzaId";
$myresult = mysqli_query($conn, $mysql);
$myrow = mysqli_fetch_assoc($myresult);
$pizzaName = $myrow['pizzaName'];
$pizzaPrice = $myrow['pizzaPrice'];
$total = $pizzaPrice * $Quantity;
$counter++;
$totalPrice = $totalPrice + $total;
echo '<tr>
<td>' . $counter . '</td>
<td>' . $pizzaName . '</td>
<td>' . $pizzaPrice . '</td>
<td>
<form id="frm' . $pizzaId . '">
<input type="hidden" name="pizzaId" value="' . $pizzaId . '">
<input type="number" name="quantity" value="' . $Quantity . '" class="text-center" onchange="updateCart(' . $pizzaId . ')" onkeyup="return false" style="width:60px" min=1 oninput="check(this)" onClick="this.select();">
</form>
</td>
<td>' . $total . '</td>
<td>
<form action="partials/_manageCart.php" method="POST">
<button name="removeItem" class="btn btn-sm btn-outline-danger">Remove</button>
<input type="hidden" name="itemId" value="'.$pizzaId. '">
</form>
</td>
</tr>';
}
if($counter==0) {
?><script> document.getElementById("cont").innerHTML = '<div class="col-md-12 my-5"><div class="card"><div class="card-body cart"><div class="col-sm-12 empty-cart-cls text-center"> <img src="https://i.imgur.com/dCdflKN.png" width="130" height="130" class="img-fluid mb-4 mr-3"><h3><strong>Your Cart is Empty</strong></h3><h4>Add something to make me happy :)</h4> <a href="index.php" class="btn btn-primary cart-btn-transform m-3" data-abc="true">continue shopping</a> </div></div></div></div>';</script> <?php
}
?>
</tbody>
</table>
</div>
</div>
<div class="col-lg-4">
<div class="card wish-list mb-3">
<div class="pt-4 border bg-light rounded p-3">
<h5 class="mb-3 text-uppercase font-weight-bold text-center">Order summary</h5>
<ul class="list-group list-group-flush">
<li class="list-group-item d-flex justify-content-between align-items-center border-0 px-0 pb-0 bg-light">Total Price<span>Rs. <?php echo $totalPrice ?></span></li>
<li class="list-group-item d-flex justify-content-between align-items-center px-0 bg-light">Shipping<span>Rs. 0</span></li>
<li class="list-group-item d-flex justify-content-between align-items-center border-0 px-0 mb-3 bg-light">
<div>
<strong>The total amount of</strong>
<strong><p class="mb-0">(including Tax & Charge)</p></strong>
</div>
<span><strong>Rs. <?php echo $totalPrice ?></strong></span>
</li>
</ul>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault1" checked>
<label class="form-check-label" for="flexRadioDefault1">
Cash On Delivery
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault1" id="flexRadioDefault1" disabled>
<label class="form-check-label" for="flexRadioDefault1">
Online Payment
</label>
</div><br>
<button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#checkoutModal">go to checkout</button>
</div>
</div>
<div class="mb-3">
<div class="pt-4">
<a class="dark-grey-text d-flex justify-content-between" style="text-decoration: none; color: #050607;" data-toggle="collapse" href="#collapseExample"
aria-expanded="false" aria-controls="collapseExample">
Add a discount code (optional)
<span><i class="fas fa-chevron-down pt-1"></i></span>
</a>
<div class="collapse" id="collapseExample">
<div class="mt-3">
<div class="md-form md-outline mb-0">
<input type="text" id="discount-code" class="form-control font-weight-light"
placeholder="Enter discount code">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
else {
echo '<div class="container" style="min-height : 610px;">
<div class="alert alert-info my-3">
<font style="font-size:22px"><center>Before checkout you need to <strong><a class="alert-link" data-toggle="modal" data-target="#loginModal">Login</a></strong></center></font>
</div></div>';
}
?>
<?php require 'partials/_checkoutModal.php'; ?>
<?php require 'partials/_footer.php' ?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]/dist/bootstrap-show-password.min.js"></script>
<script>
function check(input) {
if (input.value <= 0) {
input.value = 1;
}
}
function updateCart(id) {
$.ajax({
url: 'partials/_manageCart.php',
type: 'POST',
data:$("#frm"+id).serialize(),
success:function(res) {
location.reload();
}
})
}
</script>
</body>
</html>