Repository navigation
Expand file tree
/
Copy pathcart.php
More file actions
74 lines (73 loc) · 3.49 KB
/
Copy pathcart.php
File metadata and controls
74 lines (73 loc) · 3.49 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
<?php require_once('inc/header.php'); ?>
<?php //include "handlers/product/add-to-cart.php"
?>
<!-- Header-->
<header class="bg-dark py-5">
<div class="container px-4 px-lg-5 my-5">
<div class="text-center text-white">
<h1 class="display-4 fw-bolder">Shop in style</h1>
<p class="lead fw-normal text-white-50 mb-0">With this shop homepage template</p>
</div>
</div>
</header>
<!-- Section-->
<section class="py-5">
<div class="container px-4 px-lg-5 mt-5">
<div class="row">
<div class="col-12">
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Product</th>
<th scope="col">Price</th>
<th scope="col">Quantity</th>
<th scope="col">Total</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
<?php if (isset($_SESSION['cart']) && !empty($_SESSION['cart'])): ?>
<?php $total = 0; ?>
<?php foreach ($_SESSION['cart'] as $index => $item): ?>
<tr>
<th scope="row"><?php echo $index + 1; ?></th>
<td><?php echo $item['name']; ?></td>
<td>$<?php echo $item['price']; ?></td>
<td>
<input type="number" value="<?php echo $item['quantity']; ?>" min="1" readonly>
</td>
<td>$<?php echo $item['price'] * $item['quantity']; ?></td>
<td>
<form action='handlers/product/remove-from-cart.php' method='POST'>
<input type="hidden" name="id" value="<?php echo $item['id']; ?>">
<button type='submit' class='btn btn-danger btn-small'>Delete</button>
</form>
</td>
</tr>
<?php $total += $item['price'] * $item['quantity']; ?>
<?php endforeach; ?>
<tr>
<td colspan="2">
Total Price
</td>
<td colspan="3">
<h3>$<?php echo $total; ?></h3>
</td>
<td>
<form action='handlers/product/checkout.php' method='POST'>
<button type='submit' class='btn btn-dark btn-small'>Checkout</button>
</form>
</td>
</tr>
<?php else: ?>
<tr>
<td colspan="6" class="text-center">Your cart is empty.</td>
</tr>
<?php endif; ?>
</table>
</div>
</div>
</div>
</section>
<?php require_once('inc/footer.php'); ?>