-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout.php
138 lines (125 loc) · 5.91 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
<?php include "components/footer.php" ?>
<?php include "components/navbar.php" ?>
<?php include "php/helper.php" ?>
<?php
$email = getSignedEmail();
if(!$email){
header("Location: signin.php");
}
$user = get("SELECT U.fname, U.lname, A.* FROM users U RIGHT OUTER JOIN user_addresses A ON U.email=A.email WHERE A.email=\"$email\"");
$fname = $user["fname"];
$lname = $user["lname"];
$name = $fname." ".$lname;
$line1 = $user["line1"];
$line2 = $user["line2"];
$city = $user["city"];
$province = $user["province"];
$zip = $user["zip"];
$orderId = generateOrderId();
// calculate sub total and grand total
$subTotal = get("SELECT SUM(B.price*C.quantity) 'total' FROM cart C RIGHT OUTER JOIN books B ON C.isbn=B.isbn WHERE email=\"$email\"")["total"];
$deliveryFee = 300;
$grandTotal = $deliveryFee + $subTotal;
function showOrderSummery(){
global $email, $subTotal, $grandTotal, $deliveryFee;
$orderItems = execute("SELECT B.name, B.price, C.quantity, B.price*C.quantity 'total' FROM cart C RIGHT OUTER JOIN books B ON C.isbn=B.isbn WHERE email=\"$email\"");
foreach ($orderItems as $item) {
// var_dump($item);
$item = "
<tr style='border-bottom: solid #ccc 1px;'>
<td class='text-secondary pt-2'><strong>".$item["name"]."</strong><br><small>RS. ".number_format($item["price"], 2)." × ".$item["quantity"]."</small></td>
<td class='text-end pt-2'><strong>Rs. ".number_format($item["total"], 2)."</strong></td>
</tr>
";
// print_r($item["total"]);
echo $item;
}
}
?>
<!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">
<!-- custom css -->
<link rel="stylesheet" href="css/cart.css">
<title>BookBae | Checkout</title>
<style>
.cCart{
border-radius: 20px;
margin-bottom: 1rem;
}
</style>
</head>
<body>
<!-- Navbar starts -->
<?php navbar(""); ?>
<!-- Navbar ends -->
<!-- Page content starts -->
<div class="container my-3">
<div class="row">
<div class="col">
<h2 class="mb-2">Checkout</h2>
<div class="hr mb-3 mb-md-4"></div>
</div>
<div class="col-auto d-flex align-items-center d-none d-md-block">
<a href="cart.php" class="btn bg-brown text-white"><i class="bi bi-arrow-left"></i> <strong>Back to cart</strong></a>
</div>
</div>
<form action="php/placeOrder.php" method="post">
<div class="row">
<div class="col-md-7">
<div class="cCart p-3 p-md-5 bg-light">
<h3><strong>Order #<?php echo $orderId; ?></strong></h3>
<h4 class="text-brown">Rs. <?php echo number_format($grandTotal, 2) ?></h4>
<h5 class="mt-3 mb-1"><strong>Address</strong></h5>
<p class="text-secondary">
<?php echo "$name<br>$line1, $line2,<br>$city,<br>$province.<br>$zip"; ?>
</p>
</div>
<div class="cCart p-3 p-md-5 bg-light">
<h4><strong>Order notes</strong></h4>
<div class="input-group">
<textarea class="form-control font-sf-pro" rows="3" name="note" placeholder="Add custon notes"></textarea>
</div>
</div>
</div>
<div class="col-md-5">
<div class="cCart p-3 p-md-5 bg-light">
<h5><strong>Order summery</strong></h5>
<table class="w-100" style="border-spacing: 0 50px;">
<?php showOrderSummery(); ?>
<tr>
<td class="text-secondary" style="padding-top: 1rem;"><strong>Sub total</strong></td>
<td class="text-end" style="padding-top: 1rem;"><strong>Rs. <?php echo number_format($subTotal, 2) ?></strong></td>
</tr>
<tr>
<td class="text-secondary"><strong>Delivery fees</strong></td>
<td class="text-end"><strong>Rs. <?php echo number_format($deliveryFee, 2) ?></strong></td>
</tr>
<tr style="border-top: solid #ccc 1px;">
<td style="padding-top: 1rem;"><strong>Grand total</strong></td>
<td class="text-end" style="padding-top: 1rem;"><strong>Rs. <?php echo number_format($grandTotal, 2) ?></strong></td>
</tr>
</table>
<input type="hidden" name="fname" value="<?php echo $fname; ?>">
<input type="hidden" name="lname" value="<?php echo $lname; ?>">
<input type="hidden" name="address" value="<?php echo $line1.", ".$line2; ?>">
<input type="hidden" name="city" value="<?php echo $city; ?>">
<input type="hidden" name="email" value="<?php echo $email; ?>">
<input type="hidden" name="id" value="<?php echo $orderId; ?>">
<input type="hidden" name="total" value="<?php echo $grandTotal; ?>">
<button type="submit" class="btn bg-brown text-white mt-3 w-100 py-2"><strong>Place order</strong> <i class="bi bi-arrow-right"></i></button>
</div>
</div>
</div>
</form>
</div>
<!-- Page content ends -->
<!-- Footer starts -->
<?php footer(); ?>
<!-- Footer ends -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>