-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcart.php
51 lines (43 loc) · 1.39 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
<?php session_start();
if(isset($_GET['action'])){
if($_GET['action'] == 'empty'){
unset($_SESSION["cart_item"]);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/main.css">
<title>Cart</title>
</head>
<body>
<a class="homeButton" href="/eshop/index.php">Home Page</a>
<div id="flexcontainer">
<?php
require_once("controller.php");
$db_handle = new controller();
$product_array = $db_handle->runQuery("SELECT `id`, `title`, `price`, `image`, `productcategory_id` FROM `products` ORDER BY id ASC");
if (!empty($product_array) && !empty($_SESSION["cart_item"])) {
foreach($_SESSION["cart_item"] as $key=>$value){
foreach($product_array as $product){
if($product['id'] == $value['code']){
?>
<div class="item">
<div class="product-image"><img src="<?php echo $product["image"]; ?>" width="200" height="200"></div>
<div class="label"><strong><?php echo $product["title"]; ?></strong></div>
<div class="label"><strong>Quantity: <?php echo $value["quantity"]; ?></strong></div>
<div class="label">Total Price: <?php echo "$".(int)$product["price"]*(int)$value["quantity"]; ?></div>
</div>
<?php
}
}
}
}
?>
</div>
<button class="cashoutbutton">cash out</button>
<a class="cashoutbutton" href="?action=empty">empty cart</button>
</body>
</html>