-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
131 lines (119 loc) · 4.77 KB
/
cart.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
<?php include "components/footer.php" ?>
<?php include "components/navbar.php" ?>
<?php include "components/item.php" ?>
<?php
//if user is not signed in
if(!isSigned()){
header("Location: signin.php");
}
//get user email
$email = getSignedEmail();
$deliveryFee = 300;
$subTotal = 0;
$grandTotal = $subTotal + $deliveryFee;
$items = execute("SELECT C.isbn, B.name, B.author, 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\"");
function showCartItems(){
global $items, $email, $subTotal, $grandTotal, $deliveryFee;
foreach ($items as $item) {
//book details
$isbn = $item["isbn"];
$name = $item["name"];
$author = $item["author"];
$price = $item["price"];
$quantity = $item["quantity"];
$itemTotal = $item["total"];
//calculating sub total
$subTotal += $itemTotal;
cartItem($isbn, $name, $author, $price, $quantity, $itemTotal);
}
//calculating grand total
$grandTotal = $subTotal + $deliveryFee;
}
$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\"");
$name = $user["fname"]." ".$user["lname"];
$line1 = $user["line1"];
$line2 = $user["line2"];
$city = $user["city"];
$province = $user["province"];
$zip = $user["zip"];
?>
<!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 | Cart</title>
</head>
<body>
<!-- Navbar starts -->
<?php navbar("cart"); ?>
<!-- Navbar ends -->
<!-- Page content starts -->
<div class="container my-3">
<div class="row">
<div class="col">
<h2 class="mb-2">My Cart</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="search.php?q=" class="btn bg-brown text-white"><i class="bi bi-arrow-left"></i> <strong>Continue shopping</strong></a>
</div>
</div>
<h2 class="text-center my-5 <?php echo $items->num_rows!=0?"d-none":""; ?>">You don't have any cart items yet...!</h2>
<div class="table-responsive <?php echo $items->num_rows==0?"d-none":""; ?>">
<table class="table table-hover overflow-scroll">
<thead class="text-secondary">
<tr>
<th scope="col">PRODUCT</th>
<th scope="col">PRICE</th>
<th scope="col" class="text-center">QTY</th>
<th scope="col">TOTAL</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php showCartItems(); ?>
</tbody>
</table>
</div>
<section class="cart-bottom-section my-4 p-4 px-5 <?php echo $items->num_rows==0?"d-none":""; ?>">
<div class="row">
<div class="col-sm-5 mb-4 mb-md-0">
<h4>Address</h4>
<p class="text-secondary">
<?php echo "$name<br>$line1, $line2, $city,<br>$province.<br>$zip"; ?>
</p>
</div>
<div class="col"></div>
<div class="col-sm-5 col-md-3 d-grid">
<table class="w-100 total-table">
<tr>
<th class="text-secondary">Subtotal</th>
<th class="text-end">Rs. <?php echo number_format($subTotal, 2); ?></th>
</tr>
<tr>
<th class="text-secondary">Delivery</th>
<th class="text-end">Rs. <?php echo number_format($deliveryFee, 2); ?></th>
</tr>
<tr><td colspan="2"><hr></td></tr>
<tr>
<th class="text-secondary">Total</th>
<th class="text-end">Rs. <?php echo number_format($grandTotal, 2); ?></th>
</tr>
</table>
<a href="checkout.php" class="btn proceed-to-checkout-btn mt-3 py-1"><strong>Proceed to checkout</strong></a>
<div></div>
</div>
</div>
</section>
</div>
<!-- Page content ends -->
<!-- Footer starts -->
<?php footer(); ?>
<!-- Footer ends -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>