-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.class.php
85 lines (70 loc) · 1.68 KB
/
cart.class.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
<?php
class CartItem {
private $id;
private $name;
private $price;
private $qty;
private $customizations = array();
function __construct($id, $name, $price, $qty) {
$this->id = $id;
$this->name = $name;
$this->price = $price;
$this->qty = $qty;
}
function addCustomization($id, $name, $price) {
array_push($this->customizations, new Customization($id, $name, $price));
}
function removeCustomization($id) {
$pos = -1;
for($i = 0; $i < count($this->customizations); $i++) {
if($this->customizations[$i]->getId() == $id) {
$pos = $i;
break;
}
}
if($pos != -1) {
unset($this->customizations[$pos]);
$this->customizations = array_values($this->customizations);
return true;
} else {
return false;
}
}
function getID() {
return $this->id;
}
function getName() {
return $this->name;
}
function getPrice() {
return $this->price;
}
function getQty() {
return $this->qty;
}
function getCustomizations() {
return $this->customizations;
}
function setQty($qty) {
$this->qty = $qty;
}
}
class Customization {
private $id;
private $name;
private $price;
function __construct($id, $name, $price) {
$this->id = $id;
$this->name = $name;
$this->price = $price;
}
function getId() {
return $this->id;
}
function getName() {
return $this->name;
}
function getPrice() {
return $this->price;
}
}