/
view_cart.php
70 lines (65 loc) · 1.76 KB
/
view_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
<?php
include 'includes/database.include.php';
$loggedIn = check_login();
if(!$loggedIn) {
header('Location: /');
}
if(!isset($_SESSION['shopping_cart'])) {
header('Location: /');
}
$pageName = "View Cart";
include('templates/head.php');
include('templates/navigation.php');
?>
<div class="jumbotron">
<div class="container">
<h1>Your shopping cart</h1>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Image</th>
<th>Name</th>
<th>Price</th>
<th>Count</th>
<th>Sum</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$rows = $_SESSION['shopping_cart'];
$result = get_shopping_cart_items($pdo);
foreach ($result as $row) {
// var_dump($row);
// die();
?>
<tr>
<td><img src="images/<?php echo $row[0]['image']; ?>" style="max-height: 50px; max-width: 50px;"></td>
<td><?php echo $row[0]['productname']; ?></td>
<td><?php echo $row[0]['price'].' $'; ?></td>
<td><?php echo $row['count']; ?></td>
<td><?php echo $row['count']*$row[0]['price'].' $'; ?></td>
<td><a href="remove_from_cart.php?id=<?php echo $row[0]['id'];?>" class="btn btn-default" id="<?php echo $row[0]['id']; ?>">Remove from cart</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
if(get_shopping_cart_value($pdo) != 0) {
echo 'Sum of costs: '.get_shopping_cart_value($pdo).' $';
echo '<a href="checkout.php" class="pull-right btn btn-success">Checkout</a> ';
}
?>
</div>
</div>
</div>
<?php
include 'templates/footer.html';
?>