-
Notifications
You must be signed in to change notification settings - Fork 0
/
view-cart.php
79 lines (77 loc) · 2.02 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
71
72
73
74
75
76
77
78
79
<?php
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
$cookie_data = stripslashes($_COOKIE['shopping_cart']);
$cart_data = json_decode($cookie_data, true);
foreach($cart_data as $keys => $values)
{
if($cart_data[$keys]['item_id'] == $_GET["id"])
{
unset($cart_data[$keys]);
$item_data = json_encode($cart_data);
setcookie("shopping_cart", $item_data, time() + (86400 * 30));
header("location:index.php?remove=1");
}
}
}
if($_GET["action"] == "clear")
{
setcookie("shopping_cart", "", time() - 3600);
header("location:index.php?clearall=1");
}
}
?>
<h3>Order Details</h3>
<div class="table-responsive">
<?php echo isset($message)? $message: ''; ?>
<div align="right">
<a href="cart2.php?action=clear"><b>Clear Cart</b></a>
</div>
<table class="table table-bordered">
<tr>
<th width="40%">Item Name</th>
<th width="10%">Quantity</th>
<th width="20%">Price</th>
<th width="15%">Total</th>
<th width="5%">Action</th>
</tr>
<?php
if(isset($_COOKIE["shopping_cart"]))
{
$total = 0;
$cookie_data = stripslashes($_COOKIE['shopping_cart']);
$cart_data = json_decode($cookie_data, true);
foreach($cart_data as $keys => $values)
{
?>
<tr>
<td><?php echo $values["item_name"]; ?></td>
<td><?php echo $values["item_quantity"]; ?></td>
<td>$ <?php echo $values["item_price"]; ?></td>
<td>$ <?php echo number_format($values["item_quantity"] * $values["item_price"], 2);?></td>
<td><a href="cart2.php?action=delete&id=<?php echo $values["item_id"]; ?>"><span class="text-danger">Remove</span></a></td>
</tr>
<?php
$total = $total + ($values["item_quantity"] * $values["item_price"]);
}
?>
<tr>
<td colspan="3" align="right">Total</td>
<td align="right">$ <?php echo number_format($total, 2); ?></td>
<td></td>
</tr>
<?php
}
else
{
echo '
<tr>
<td colspan="5" align="center">No Item in Cart</td>
</tr>
';
}
?>
</table>
</div>