Repository navigation
Expand file tree
/
Copy pathShowCart.php
More file actions
98 lines (82 loc) · 2.19 KB
/
Copy pathShowCart.php
File metadata and controls
98 lines (82 loc) · 2.19 KB
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
<?php
include_once 'lib/DBHelper.php';
include_once 'lib/ShoppingCart.php';
$dbh = new DBHelper();
session_start();
$shoppingCart = $_SESSION[SHOPPING_CART];
session_write_close();
?>
<html>
<head>
<link rel="stylesheet" href="roncabeanz_style.css" type="text/css" />
<link href="css/Header.css" rel="stylesheet" type="text/css">
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 80%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<div class="container">
<?php include 'Header.php'; ?>
</div>
<div class="row"></div>
<h1>Your Shopping Cart</h1>
<?php
//Step2
?>
<table>
<tr>
<th>Item</th>
<th>Qty</th>
<th>Name</th>
<th>Price</th>
<th>Item Total</th>
</tr>
<?php
if($shoppingCart != null){
$totalCost = 0;
for ($i = 0; $i < count($shoppingCart->getCartItems()); ++$i){
echo '<tr>';
$item = $shoppingCart->getCartItems()[$i];
$query = "SELECT name, country, price FROM Roncabeanz.Coffee WHERE productCode = $item->productId ORDER BY 'name'";
$result = $dbh->query($query);
$row = mysqli_fetch_array($result);
echo '<td>', $i, '</td>';
echo '<td>', $item->count, ' ', '</td>';
echo '<td>',$row["country"] , ' ', $row["name"], '</td>';
$totalCost += ($item->count * $row["price"]);
echo '<td>', $row["price"], '</td>';
echo '<td>', $item->count * $row["price"], '</td>';
echo '</tr>';
}
echo '<tr><td></td><td></td><td>Total</td><td></td><td>', $totalCost, '</td></tr>';
}
?>
</table>
<div>
<?php
if($shoppingCart != null AND !$shoppingCart->isEmpty())
{
?>
<a href="Purchase.php">Purchase</a>
<?php
}
?>
</div>
<?php
//Step 4
$dbh->close();
?>
</body>
</html>