1 | <?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
||
29 | class EE_Cart { |
||
30 | |||
31 | /** |
||
32 | * instance of the EE_Cart object |
||
33 | * @access private |
||
34 | * @var EE_Cart $_instance |
||
35 | */ |
||
36 | private static $_instance = NULL; |
||
37 | |||
38 | /** |
||
39 | * instance of the EE_Session object |
||
40 | * @access protected |
||
41 | * @var EE_Session $_session |
||
42 | */ |
||
43 | protected $_session = NULL; |
||
44 | |||
45 | /** |
||
46 | * The total Line item which comprises all the children line-item subtotals, |
||
47 | * which in turn each have their line items. |
||
48 | * Typically, the line item structure will look like: |
||
49 | * grand total |
||
50 | * -tickets-sub-total |
||
51 | * --ticket1 |
||
52 | * --ticket2 |
||
53 | * --... |
||
54 | * -taxes-sub-total |
||
55 | * --tax1 |
||
56 | * --tax2 |
||
57 | * @var EE_Line_Item |
||
58 | */ |
||
59 | private $_grand_total = NULL; |
||
60 | |||
61 | |||
62 | |||
63 | /** |
||
64 | * @singleton method used to instantiate class object |
||
65 | * @access public |
||
66 | * @param EE_Line_Item $grand_total |
||
67 | * @param EE_Session $session |
||
68 | * @return \EE_Cart |
||
69 | */ |
||
70 | public static function instance( EE_Line_Item $grand_total = null, EE_Session $session = null ) { |
||
90 | |||
91 | |||
92 | |||
93 | /** |
||
94 | * private constructor to prevent direct creation |
||
95 | * @Constructor |
||
96 | * @access private |
||
97 | * @param EE_Line_Item $grand_total |
||
98 | * @param EE_Session $session |
||
99 | * @return \EE_Cart |
||
|
|||
100 | */ |
||
101 | private function __construct( EE_Line_Item $grand_total = null, EE_Session $session = null ) { |
||
108 | |||
109 | |||
110 | |||
111 | /** |
||
112 | * Resets the cart completely (whereas empty_cart |
||
113 | * @param EE_Line_Item $grand_total |
||
114 | * @param EE_Session $session |
||
115 | * @return EE_Cart |
||
116 | */ |
||
117 | public static function reset( EE_Line_Item $grand_total = null, EE_Session $session = null ) { |
||
125 | |||
126 | |||
127 | |||
128 | /** |
||
129 | * @param EE_Session $session |
||
130 | */ |
||
131 | public function set_session( EE_Session $session = null ) { |
||
134 | |||
135 | |||
136 | |||
137 | /** |
||
138 | * Sets the cart to match the line item. Especially handy for loading an old cart where you |
||
139 | * know the grand total line item on it |
||
140 | * @param EE_Line_Item $line_item |
||
141 | */ |
||
142 | public function set_grand_total_line_item( EE_Line_Item $line_item ) { |
||
145 | |||
146 | |||
147 | |||
148 | /** |
||
149 | * get_cart_from_reg_url_link |
||
150 | * @access public |
||
151 | * @param EE_Transaction $transaction |
||
152 | * @param EE_Session $session |
||
153 | * @return \EE_Cart |
||
154 | */ |
||
155 | public static function get_cart_from_txn( EE_Transaction $transaction, EE_Session $session = null ) { |
||
161 | |||
162 | |||
163 | |||
164 | /** |
||
165 | * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
||
166 | * @return EE_Line_Item |
||
167 | */ |
||
168 | private function _create_grand_total(){ |
||
172 | |||
173 | |||
174 | |||
175 | /** |
||
176 | * Gets all the line items of object type Ticket |
||
177 | * @access public |
||
178 | * @return \EE_Line_Item[] |
||
179 | */ |
||
180 | public function get_tickets() { |
||
183 | |||
184 | |||
185 | |||
186 | /** |
||
187 | * returns the total quantity of tickets in the cart |
||
188 | * |
||
189 | * @access public |
||
190 | * @return int |
||
191 | */ |
||
192 | public function all_ticket_quantity_count() { |
||
203 | |||
204 | |||
205 | |||
206 | /** |
||
207 | * Gets all the tax line items |
||
208 | * @return \EE_Line_Item[] |
||
209 | */ |
||
210 | public function get_taxes(){ |
||
213 | |||
214 | |||
215 | |||
216 | /** |
||
217 | * Gets the total line item (which is a parent of all other line items) on this cart |
||
218 | * @return EE_Line_Item |
||
219 | */ |
||
220 | public function get_grand_total(){ |
||
223 | |||
224 | |||
225 | |||
226 | /** |
||
227 | * @process items for adding to cart |
||
228 | * @access public |
||
229 | * @param EE_Ticket $ticket |
||
230 | * @param int $qty |
||
231 | * @return TRUE on success, FALSE on fail |
||
232 | */ |
||
233 | public function add_ticket_to_cart( EE_Ticket $ticket, $qty = 1 ) { |
||
237 | |||
238 | |||
239 | |||
240 | /** |
||
241 | * get_cart_total_before_tax |
||
242 | * @access public |
||
243 | * @return float |
||
244 | */ |
||
245 | public function get_cart_total_before_tax() { |
||
248 | |||
249 | |||
250 | |||
251 | /** |
||
252 | * gets the total amount of tax paid for items in this cart |
||
253 | * @access public |
||
254 | * @return float |
||
255 | */ |
||
256 | public function get_applied_taxes() { |
||
259 | |||
260 | |||
261 | |||
262 | /** |
||
263 | * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
||
264 | * @access public |
||
265 | * @return float |
||
266 | */ |
||
267 | public function get_cart_grand_total() { |
||
271 | |||
272 | |||
273 | |||
274 | /** |
||
275 | * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
||
276 | * @access public |
||
277 | * @return float |
||
278 | */ |
||
279 | public function recalculate_all_cart_totals() { |
||
286 | |||
287 | |||
288 | |||
289 | /** |
||
290 | * deletes an item from the cart |
||
291 | * @access public |
||
292 | * @param array|bool|string $line_item_codes |
||
293 | * @return int on success, FALSE on fail |
||
294 | */ |
||
295 | public function delete_items( $line_item_codes = FALSE ) { |
||
299 | |||
300 | |||
301 | |||
302 | /** |
||
303 | * @remove ALL items from cart and zero ALL totals |
||
304 | * @access public |
||
305 | * @return bool |
||
306 | */ |
||
307 | public function empty_cart() { |
||
312 | |||
313 | |||
314 | |||
315 | /** |
||
316 | * @remove ALL items from cart and delete total as well |
||
317 | * @access public |
||
318 | * @return bool |
||
319 | */ |
||
320 | public function delete_cart() { |
||
328 | |||
329 | |||
330 | |||
331 | /** |
||
332 | * @save cart to session |
||
333 | * @access public |
||
334 | * @param bool $apply_taxes |
||
335 | * @return TRUE on success, FALSE on fail |
||
336 | */ |
||
337 | public function save_cart( $apply_taxes = TRUE ) { |
||
352 | |||
353 | |||
354 | |||
355 | |||
356 | |||
357 | } |
||
358 | /* End of file EE_Cart.core.php */ |
||
360 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.