-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.php
executable file
·207 lines (188 loc) · 7.68 KB
/
checkout.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#F7922F">
<title>Checkout | RestroHub</title>
<link rel="shortcut icon" href="./images/logo.png" type="image/x-icon">
<link rel="stylesheet" href="./styles/style.css">
<link rel="stylesheet" href="./styles/responsive.css">
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script type="module" src="./js/app.js"></script>
</head>
<body>
<?php
require './components/header.php';
if (!isset($_SESSION['success'])) {
header('Location: ./index.php');
}
?>
<main class="checkout_page" style="margin: 0 40px 40px;">
<button class="go_top no_bg no_outline"><img src="./images/ic_top.svg" alt="go to top"></button>
<?php
if (isset($_SESSION["name_error"])) {
?>
<p class="error-container error p_7-20">
<?php echo $_SESSION["name_error"]; ?>
</p>
<?php
unset($_SESSION["name_error"]);
}
?>
<?php
if (isset($_SESSION["phone_error"])) {
?>
<p class="error-container error p_7-20">
<?php echo $_SESSION["phone_error"]; ?>
</p>
<?php
unset($_SESSION["phone_error"]);
}
if (isset($_SESSION["address_error"])) {
?>
<p class="error-container error p_7-20">
<?php echo $_SESSION["address_error"]; ?>
</p>
<?php
unset($_SESSION["address_error"]);
}
?>
<?php
if (isset($_SESSION['note_error'])) {
?>
<p class="error-container error p_7-20">
<?php echo $_SESSION['note_error']; ?>
</p>
<?php
unset($_SESSION['note_error']);
}
?>
<section class="mt-20">
<h2 class="heading">Checkout</h2>
</section>
<?php
require('./config.php');
$uid = $_SESSION['user'];
$sql = "select * from cart where customer_id = $uid";
$res = mysqli_query($conn, $sql) or die("Could not fetch food items from database");
if (isset($_SESSION['delete_success'])) {
?>
<!-- to show error alert -->
<p class="error-container success p_7-20">
<?php
echo $_SESSION['delete_success'];
unset($_SESSION['delete_success']);
?>
</p>
<?php
}
if (isset($_SESSION['delete_error'])) {
?>
<p class="error-container error p_7-20">
<?php
echo $_SESSION['delete_error'];
unset($_SESSION['delete_error']);
?>
</p>
<?php
}
if (isset($_SESSION['minimum_error'])) {
?>
<p class="error-container error p_7-20">
<?php
echo $_SESSION['minimum_error'];
unset($_SESSION['minimum_error']);
?>
</p>
<?php
}
if (mysqli_num_rows($res) > 0) {
?>
<div class="checkout_table">
<table class="mt-20">
<tr class="shadow">
<th>SN</th>
<th>Image</th>
<th>Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Total Price</th>
<th>Action</th>
</tr>
<?php
$i = 0;
$totalPrice = 0;
$food_id_arr = array();
$qty_arr = array();
while ($row = mysqli_fetch_assoc($res)) {
$i++;
$food_id = $row['food_id'];
$sql_food = "select * from food where f_id = $food_id";
$res_food = mysqli_query($conn, $sql_food) or die("Could not fetch food details from database");
$row_food = mysqli_fetch_assoc($res_food);
$cart_id = $row['id'];
$foodName = $row_food['name'];
$foodPrice = $row_food['price'];
$quantity = $row['quantity'];
$totalPrice += $foodPrice * $row['quantity'];
$foodImg = $row_food['img'];
$vat = ($totalPrice * 13) / 100;
array_push($food_id_arr, $food_id);
array_push($qty_arr, $quantity);
?>
<tr class="shadow">
<td>
<?php echo $i; ?>
</td>
<td>
<img src="./uploads/foods/<?php echo $foodImg; ?>" alt="food image" class="table_food-img">
</td>
<td>
<div class="w-fit" style="margin: auto;">
<a href="./details.php?name=<?php echo str_replace(" ", "-", strtolower($foodName)); ?>">
<?php echo $foodName; ?>
</a>
<hr>
</div>
</td>
<td>
<form action="#" method="post" class="flex items-center justify-evenly checkout_item-form">
<button type="button" class="cart_item-btn checkout_inc no_bg no_outline"><img src="./images/ic_add.svg" alt="increment"></button>
<input type="text" name="quantity" class="cart_qty no_bg no_outline" value="<?php echo $quantity; ?>" disabled>
<input type="hidden" name="id" value="<?php echo $cart_id; ?>">
<input type="hidden" name="from_checkout">
<button type="button" class="cart_item-btn checkout_dec no_bg no_outline"><img src="./images/ic_remove.svg" alt="decrement"></button>
</form>
</td>
<td>
<?php echo $foodPrice; ?>
</td>
<td>
<?php echo $foodPrice * $quantity; ?>
</td>
<td>
<form action="./backend/remove-from-cart.php" method="post" class="checkout_content-form">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<button type="submit" class="no_bg no_outline btn_remove-from-checkout">
<img src="./images/ic_delete.svg" alt="remove from cart">
</button>
</form>
</td>
</tr>
<?php
}
?>
</table>
</div>
<?php
$isFromCheckout = true;
require './components/checkout-form.php';
?>
<?php
} else
echo "No records found";
?>
</main>
<?php require './components/get-footer-script.php'; ?>