1 | <?php |
||
9 | class Cart implements ArrayAccess, IteratorAggregate |
||
10 | { |
||
11 | /** |
||
12 | * $items. |
||
13 | * |
||
14 | * @var \Illuminate\Support\Collection |
||
15 | */ |
||
16 | public $items; |
||
17 | |||
18 | /** |
||
19 | * @param \Recca0120\Cart\Storage $storage |
||
20 | */ |
||
21 | protected $storage; |
||
22 | |||
23 | /** |
||
24 | * __construct. |
||
25 | * |
||
26 | * @param \Recca0120\Cart\Storage $storage |
||
27 | */ |
||
28 | 1 | public function __construct(Storage $storage = null) |
|
33 | |||
34 | /** |
||
35 | * __destruct. |
||
36 | */ |
||
37 | 1 | public function __destruct() |
|
41 | |||
42 | /** |
||
43 | * put. |
||
44 | * |
||
45 | * @param \Recca0120\Cart\Item $item |
||
46 | * @return $this |
||
47 | */ |
||
48 | 1 | public function put(Item $item) |
|
54 | |||
55 | /** |
||
56 | * get. |
||
57 | * |
||
58 | * @param string $itemId |
||
59 | * @return $this |
||
60 | */ |
||
61 | public function get($itemId) |
||
65 | |||
66 | /** |
||
67 | * remove. |
||
68 | * |
||
69 | * @param \Recca0120\Cart\Item | string $item |
||
70 | * @return \Illuminate\Support\Collection |
||
71 | */ |
||
72 | 1 | public function remove($item) |
|
73 | { |
||
74 | 1 | return $this->items->forget($item instanceof Item ? $item->getId() : $item); |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * clear. |
||
79 | * |
||
80 | * @return $this |
||
81 | */ |
||
82 | public function clear() |
||
83 | { |
||
84 | $this->items = $this->items->filter(function () { |
||
85 | return false; |
||
86 | }); |
||
87 | |||
88 | return $this; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * items. |
||
93 | * |
||
94 | * @return \Illuminate\Support\Collection |
||
95 | */ |
||
96 | 1 | public function items() |
|
100 | |||
101 | /** |
||
102 | * count. |
||
103 | * |
||
104 | * @return int |
||
105 | */ |
||
106 | 1 | public function count() |
|
110 | |||
111 | /** |
||
112 | * total. |
||
113 | * |
||
114 | * @return float |
||
115 | */ |
||
116 | 1 | public function total() |
|
117 | { |
||
118 | return $this->items->sum(function ($item) { |
||
119 | 1 | return $item->getPrice() * $item->getQuantity(); |
|
120 | 1 | }); |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * restore. |
||
125 | * |
||
126 | * @return $this |
||
127 | */ |
||
128 | 1 | public function restore() |
|
134 | |||
135 | /** |
||
136 | * store. |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | 1 | public function store() |
|
146 | |||
147 | /** |
||
148 | * toArray. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | public function toArray() |
||
158 | |||
159 | /** |
||
160 | * toJson. |
||
161 | * |
||
162 | * @param int $option |
||
163 | * @return string |
||
164 | */ |
||
165 | public function toJson($option = 0) |
||
169 | |||
170 | /** |
||
171 | * Determine if an item exists at an offset. |
||
172 | * |
||
173 | * @param mixed $key |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function offsetExists($key) |
||
180 | |||
181 | /** |
||
182 | * Get an item at a given offset. |
||
183 | * |
||
184 | * @param mixed $key |
||
185 | * @return mixed |
||
186 | */ |
||
187 | public function offsetGet($key) |
||
191 | |||
192 | /** |
||
193 | * Set the item at a given offset. |
||
194 | * |
||
195 | * @param mixed $key |
||
196 | * @param mixed $value |
||
197 | * @return void |
||
198 | */ |
||
199 | public function offsetSet($key, $value) |
||
203 | |||
204 | /** |
||
205 | * Unset the item at a given offset. |
||
206 | * |
||
207 | * @param string $key |
||
208 | * @return void |
||
209 | */ |
||
210 | public function offsetUnset($key) |
||
214 | |||
215 | /** |
||
216 | * Get an iterator for the items. |
||
217 | * |
||
218 | * @return \ArrayIterator |
||
219 | */ |
||
220 | public function getIterator() |
||
224 | } |
||
225 |