-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcart.php
188 lines (176 loc) · 6.48 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
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
<?php
require_once("header.php");
?>
<ul class="navbar-nav me-auto ms-4 mb-2 mb-lg-0">
<?php
if ($_SESSION['name'] == 'GUEST') {
echo "
<li class=\"nav-item\">
<a class=\"nav-link\" href=\"login.php\">Login/Register</a>
</li>
";
} else {
echo "
<li class=\"nav-item\">
<a class=\"nav-link\" href=\"dashboard.php\">Dashboard</a>
</li>
";
}
?>
<li class="nav-item">
<a class="nav-link" href="about.php">About</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-bs-toggle="dropdown" aria-expanded="false"> Categories
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="tshirt.php">T-Shirt</a></li>
<li><a class="dropdown-item" href="jacket.php">Jacket</a></li>
<li><a class="dropdown-item" href="mug.php">Mug</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="mouse.php">Mouse</a></li>
<li><a class="dropdown-item" href="keyboard.php">Keyboard</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link active" href="#">View Cart
<span class="badge rounded-pill bg-primary">
<?php
echo $_SESSION['cart'];
?>
</span>
</a>
</li>
</ul>
<!-- <form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Find products..." aria-label="Search">
<button class="btn btn-outline-secondary" type="submit">Search</button>
</form> -->
</div>
</div>
</nav>
</section>
<!-- END OF NAVIGATION PANEL -->
<div class="container h-100">
<br>
<h3><i class="fas fa-shopping-basket"></i> Shopping Cart</h3>
<?php
if ($_SESSION['name'] == 'GUEST') {
if (!isset($_SESSION['cartlist']) || sizeof($_SESSION['cartlist']) === 0) {
echo "
<center class=\"shadow border rounded p-5\" style=\"margin-top: 55px; margin-bottom: 200px;\">
<h2>No item(s) to display..</h2><h2>Add some items at the store!</h2>
</center>";
} else {
echo " <br> <div class=\"border rounded shadow p-3\">
<div class=\"row h-100 justify-content-center align-items-center text-center p-2\">
<div class=\"col-md-3\"><b>Preview</b></div>
<div class=\"col-md-3\"><b>Name</b></div>
<div class=\"col-md-2\"><b>Price</b></div>
<div class=\"col-md-2\"><b>Quantity</b></div>
<div class=\"col-md-2\"><b>Adjustment</b></div>
</div>";
$_SESSION['total_price'] = 0;
foreach ($_SESSION['cartlist'] as $row) {
echo "
<div class=\"row h-100 justify-content-center align-items-center text-center p-2\">
<div class=\"col-md-3\">
<img src=\"".$row["image"]."\" width=150>
</div>
<div class=\"col-md-3\">
<b>".$row["name"]."</b>
</div>
<div class=\"col-md-2\">
<b>₱ ".number_format($row["price"], 2, '.', ',')."</b>
</div>
<div class=\"col-md-2\">
<b>".$row["quantity"]."</b>
</div>
<div class=\"col-md-2\">
<a href=\"includes/addtocart.inc.php?id=".$row['id']."&link=cart.php\" class=\"btn btn-success\">+</a>
<a href=\"includes/decrease.inc.php?name=".$row['name']."&link=cart.php\" class=\"btn btn-danger\">-</a>
</div>
</div>";
$_SESSION['total_price'] = $_SESSION['total_price'] + ($row["price"] * $row["quantity"]);
}
echo " <br>
<div class=\"row h-100 justify-content-center align-items-center text-center\">
<div class=\"col-md-12\">
<h4>Total: ₱ ".number_format($_SESSION['total_price'], 2, '.', ',')."</h4>
</div>
</div>";
echo "
<center>
<a href=\"includes\\resetall.inc.php?link=cart.php\" class=\"btn btn-danger me-1 px-5\">
Empty cart
</a>
<a href=\"shipping.php\" class=\"btn btn-secondary px-4\">
Proceed to checkout
</a>
</center> </div>";
}
} else {
$getcart = $conn->query("SELECT product_id, quantity FROM cart WHERE customer_id=".$_SESSION['name']);
if ($getcart->num_rows == 0) {
echo "
<center class=\"shadow border rounded p-5\" style=\"margin-top: 55px; margin-bottom: 200px;\">
<h2>No item(s) to display..</h2><h2>Add some items at the store!</h2>
</center>";
} else {
echo " <br> <div class=\"border rounded shadow p-3\">
<div class=\"row h-100 justify-content-center align-items-center text-center p-2\">
<div class=\"col-md-3\"><b>Preview</b></div>
<div class=\"col-md-3\"><b>Name</b></div>
<div class=\"col-md-2\"><b>Price</b></div>
<div class=\"col-md-2\"><b>Quantity</b></div>
<div class=\"col-md-2\"><b>Adjustment</b></div>
</div>";
$_SESSION['total_price'] = 0;
while ($row = $getcart->fetch_assoc()) {
$getproduct = $conn->query("SELECT * FROM product WHERE product_id=".($row['product_id']));
$product = $getproduct->fetch_assoc();
echo "
<div class=\"row h-100 justify-content-center align-items-center text-center p-2\">
<div class=\"col-md-3\">
<img src=\"".$product["image"]."\" width=150>
</div>
<div class=\"col-md-3\">
<b>".$product["name"]."</b>
</div>
<div class=\"col-md-2\">
<b>₱ ".number_format($product["price"], 2, '.', ',')."</b>
</div>
<div class=\"col-md-2\">
<b>".$row["quantity"]."</b>
</div>
<div class=\"col-md-2\">
<a href=\"includes/addtocart.inc.php?id=".$row['product_id']."&link=cart.php\" class=\"btn btn-success\">+</a>
<a href=\"includes/decrease.inc.php?id=".$row['product_id']."&name=".$product['name']."&link=cart.php\" class=\"btn btn-danger\">-</a>
</div>
</div>";
$_SESSION['total_price'] = $_SESSION['total_price'] + ($product["price"] * $row["quantity"]);
}
echo " <br>
<div class=\"row h-100 justify-content-center align-items-center text-center\">
<div class=\"col-md-12\">
<h4>Total: ₱ ".number_format($_SESSION['total_price'], 2, '.', ',')."</h4>
</div>
</div>";
echo "
<center>
<a href=\"includes\\resetall.inc.php?link=cart.php\" class=\"btn btn-danger me-1 px-5\">
Empty cart
</a>
<a href=\"shipping.php\" class=\"btn btn-secondary px-4\">
Proceed to checkout
</a>
</center> </div>";
}
}?>
</div>
<?php
require_once("footer.php");
?>