1 | <?php |
||
22 | class ShoppingCart extends \yz\shoppingcart\ShoppingCart |
||
23 | { |
||
24 | /** |
||
25 | * @var AbstractCartPosition[] |
||
26 | * TODO make local AbstractCartPosition |
||
27 | */ |
||
28 | protected $_positions = []; |
||
29 | |||
30 | /** |
||
31 | * The cart module. |
||
32 | */ |
||
33 | public $module; |
||
34 | |||
35 | public $currency = 'usd'; |
||
36 | |||
37 | /** |
||
38 | * @return integer |
||
39 | 1 | */ |
|
40 | public function getCount() |
||
41 | 1 | { |
|
42 | return count($this->_positions); |
||
43 | } |
||
44 | 1 | ||
45 | public function getQuantity() |
||
46 | 1 | { |
|
47 | 1 | $count = 0; |
|
48 | 1 | foreach ($this->_positions as $position) { |
|
49 | $count += $position->getQuantity(); |
||
50 | } |
||
51 | 1 | ||
52 | return $count; |
||
53 | } |
||
54 | 2 | ||
55 | public function getSubtotal() |
||
56 | 2 | { |
|
57 | return $this->getCost(false); |
||
58 | } |
||
59 | 2 | ||
60 | public function getTotal() |
||
61 | 2 | { |
|
62 | return $this->getCost(true); |
||
63 | } |
||
64 | 1 | ||
65 | public function getDiscount() |
||
66 | 1 | { |
|
67 | return $this->getTotal() - $this->getSubtotal(); |
||
68 | } |
||
69 | 1 | ||
70 | public function formatCurrency($sum, $currency = null) |
||
74 | |||
75 | /** |
||
76 | * Sets cart from serialized string |
||
77 | * @param string $serialized |
||
78 | */ |
||
79 | public function setSerialized($serialized) |
||
89 | |||
90 | /** |
||
91 | * Checks whether any of cart positions has error in `id` attribute. |
||
92 | * @return boolean |
||
93 | */ |
||
94 | public function hasErrors() |
||
104 | |||
105 | /** |
||
106 | * @param CartPositionInterface[] $positions |
||
107 | */ |
||
108 | public function putPositions($positions) |
||
131 | } |
||
132 |