-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartList.php
100 lines (86 loc) · 3.33 KB
/
cartList.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
require_once 'CartItem.php';
//require_once 'KLogger.php';
Class CartList{
private $cartItems;
protected $logger;
public function __construct(){
$this->cartItems = array();
$this->logger = new KLogger("logs/log.txt", KLogger::DEBUG);
}
public function addCartItem(CartItem $item){
$this->cartItems[$item->getID()] = $item;
}
public function removeCartItem($id){
unset($this->cartItems[$id]);
}
public function emptyCart(){
$this->cartItems = array();
}
public function returnCart(){
return $this->cartItems;
}
public function printCheckout(){
echo '<div id = "checkout">
<div id = "headerBar">
<div id = "summaryTitle">
<h3 class = "totalCheck">Cart Summary</h3>
</div>
</div>
<div id = "checkoutContent">
<div id = "checkoutAlign">
<span class = "checkoutLeft">Subtotal</span>
<span class = "checkoutRight sub">$'.$this->calculateTotal().'</span>
</div>
<div id = "checkoutAlign">
<span class = "checkoutLeft">Total Discounts</span>
<span class = "checkoutRight">None Available</span>
</div>
<div id = "checkoutAlign">
<p class = "smallText">Taxes and shipping will be calculated during checkout. <a id = "link" href = "order-policy.php">Learn More</a> about our shipping policy here</p>
</div>
<div id ="checkoutAlign">
<span class = "checkoutLeft"><h2>EST. Total</h2></span>
<span class = "checkoutRight subtotal"><h2>$'.$this->calculateTotal().'</h2></span>
</div>
<div id = "checkoutButton">
<input type = "submit" class = "greenButton" name = "checkout" value = "Checkout"/>
</div>
</div>
</div>';
}
public function printCart(){
if(count($this->cartItems)){
echo '<form id = "form" action = "cart_handler.php" method = "post">
<div id = "body">
<div id = "container">
<div id = "cartHeader">
<h2 class = "cartTitle">Your Shopping Cart</h1>
<div class = "priceHeader">Price</div>
</div>'
;
foreach($this->cartItems as $i){
$i->displayItem();
}
echo '
<div id = "total">Subtotal: $'.$this->calculateTotal().'</div>
<div id = "remove">
<input type = "submit" class = "removeAll" id = "removeSel" name = "deleteSelected" value = "Delete Selected"/>
<input type = "submit" id = "removeAll" name = "deleteAll" class = "removeAll" value = "Delete All"/>
</div>';
echo '</div></form>';
$this->printCheckout();
}
else{
echo '<div id = "container"><h1>Your cart is empty</h1></div>';
}
echo '</div>';
}
private function calculateTotal(){
$total = 0;
foreach($this->cartItems as $i){
$total += $i->getPrice();
}
return $total;
}
}