1 | <?php |
||
32 | class EEM_Line_Item extends EEM_Base |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * Tax sub-total is just the total of all the taxes, which should be children |
||
37 | * of this line item. There should only ever be one tax sub-total, and it should |
||
38 | * be a direct child of. Its quantity and LIN_unit_price = 1. |
||
39 | */ |
||
40 | const type_tax_sub_total = 'tax-sub-total'; |
||
41 | |||
42 | /** |
||
43 | * Tax line items indicate a tax applied to all the taxable line items. |
||
44 | * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
||
45 | * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
||
46 | */ |
||
47 | const type_tax = 'tax'; |
||
48 | |||
49 | /** |
||
50 | * Indicating individual items purchased, or discounts or surcharges. |
||
51 | * The sum of all the regular line items plus the tax items should equal |
||
52 | * the grand total. |
||
53 | * Possible children are sub-line-items and cancellations. |
||
54 | * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
||
55 | * LIN_totals. Its LIN_percent = 0. |
||
56 | * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
||
57 | * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
||
58 | */ |
||
59 | const type_line_item = 'line-item'; |
||
60 | |||
61 | /** |
||
62 | * Line item indicating all the factors that make a single line item. |
||
63 | * Sub-line items should have NO children line items. |
||
64 | * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
||
65 | * contribution towards the price of ONE of their parent items, and its LIN_total should be |
||
66 | * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
||
67 | * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
||
68 | * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
||
69 | */ |
||
70 | const type_sub_line_item = 'sub-item'; |
||
71 | |||
72 | /** |
||
73 | * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
||
74 | * Direct children should be event subtotals. |
||
75 | * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
||
76 | * |
||
77 | */ |
||
78 | const type_sub_total = 'sub-total'; |
||
79 | |||
80 | /** |
||
81 | * Line item for the grand total of an order. Its direct children |
||
82 | * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item |
||
83 | * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of |
||
84 | * the entire order's mount. |
||
85 | */ |
||
86 | const type_total = 'total'; |
||
87 | |||
88 | /** |
||
89 | * When a line item is cancelled, a sub-line-item of type 'cancellation' |
||
90 | * should be created, indicating the quantity that were cancelled |
||
91 | * (because a line item could have a quantity of 1, and its cancellation item |
||
92 | * could be for 3, indicating that originally 4 were purchased, but 3 have been |
||
93 | * cancelled, and only one remains). |
||
94 | * When items are refunded, a cancellation line item should be made, which points |
||
95 | * to teh payment model object which actually refunded the payment. |
||
96 | * Cancellations should NOT have any children line items; the should NOT affect |
||
97 | * any calculations, and are only meant as a record that cancellations have occurred. |
||
98 | * Their LIN_percent should be 0. |
||
99 | */ |
||
100 | const type_cancellation = 'cancellation'; |
||
101 | |||
102 | // private instance of the EEM_Line_Item object |
||
103 | protected static $_instance = null; |
||
104 | |||
105 | |||
106 | /** |
||
107 | * private constructor to prevent direct creation |
||
108 | * @Constructor |
||
109 | * @access protected |
||
110 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
||
111 | * @return \EEM_Line_Item |
||
|
|||
112 | */ |
||
113 | protected function __construct($timezone) |
||
160 | |||
161 | |||
162 | /** |
||
163 | * Gets all the line items for this transaction of the given type |
||
164 | * @param string $line_item_type like one of EEM_Line_Item::type_* |
||
165 | * @param EE_Transaction|int $transaction |
||
166 | * @return EE_Line_Item[] |
||
167 | */ |
||
168 | public function get_all_of_type_for_transaction($line_item_type, $transaction) |
||
176 | |||
177 | |||
178 | /** |
||
179 | * Gets all line items unrelated to tickets that are normal line items |
||
180 | * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
||
181 | * @param EE_Transaction|int $transaction |
||
182 | * @return EE_Line_Item[] |
||
183 | */ |
||
184 | public function get_all_non_ticket_line_items_for_transaction($transaction) |
||
195 | |||
196 | /** |
||
197 | * Deletes line items with no transaction who have passed the transaction cutoff time. |
||
198 | * This needs to be very efficient |
||
199 | * because if there are spam bots afoot there will be LOTS of line items |
||
200 | * @return int count of how many deleted |
||
201 | */ |
||
202 | public function delete_line_items_with_no_transaction() |
||
220 | |||
221 | |||
222 | /** |
||
223 | * get_line_item_for_transaction_object |
||
224 | * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
||
225 | * |
||
226 | * @param int $TXN_ID |
||
227 | * @param \EE_Base_Class $object |
||
228 | * @return EE_Line_Item[] |
||
229 | */ |
||
230 | public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
||
238 | |||
239 | |||
240 | /** |
||
241 | * get_object_line_items_for_transaction |
||
242 | * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
||
243 | * |
||
244 | * @param int $TXN_ID |
||
245 | * @param string $OBJ_type |
||
246 | * @param array $OBJ_IDs |
||
247 | * @return EE_Line_Item[] |
||
248 | */ |
||
249 | public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
||
261 | |||
262 | |||
263 | /** |
||
264 | * get_all_ticket_line_items_for_transaction |
||
265 | * |
||
266 | * @param EE_Transaction $transaction |
||
267 | * @return EE_Line_Item[] |
||
268 | */ |
||
269 | public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
||
278 | |||
279 | |||
280 | /** |
||
281 | * get_ticket_line_item_for_transaction |
||
282 | * |
||
283 | * @param int $TXN_ID |
||
284 | * @param int $TKT_ID |
||
285 | * @return \EE_Line_Item |
||
286 | */ |
||
287 | public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
||
297 | |||
298 | |||
299 | /** |
||
300 | * get_existing_promotion_line_item |
||
301 | * searches the cart for existing line items for the specified promotion |
||
302 | * |
||
303 | * @since 1.0.0 |
||
304 | * |
||
305 | * @param EE_Line_Item $parent_line_item |
||
306 | * @param EE_Promotion $promotion |
||
307 | * @return EE_Line_Item |
||
308 | */ |
||
309 | public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
||
320 | |||
321 | |||
322 | /** |
||
323 | * get_all_promotion_line_items |
||
324 | * searches the cart for any and all existing promotion line items |
||
325 | * |
||
326 | * @since 1.0.0 |
||
327 | * |
||
328 | * @param EE_Line_Item $parent_line_item |
||
329 | * @return EE_Line_Item[] |
||
330 | */ |
||
331 | public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
||
341 | |||
342 | /** |
||
343 | * Gets the registration's corresponding line item. |
||
344 | * Note: basically does NOT support having multiple line items for a single ticket, |
||
345 | * which would happen if some of the registrations had a price modifier while others didn't. |
||
346 | * In order to support that, we'd probably need a LIN_ID on registrations or something. |
||
347 | * @param EE_Registration $registration |
||
348 | * @return EE_Line_ITem |
||
349 | */ |
||
350 | public function get_line_item_for_registration(EE_Registration $registration) |
||
354 | |||
355 | /** |
||
356 | * Gets the query params used to retrieve a specific line item for the given registration |
||
357 | * @param EE_Registration $registration |
||
358 | * @param array $original_query_params any extra query params you'd like to be merged with |
||
359 | * @return array like EEM_Base::get_all()'s $query_params |
||
360 | */ |
||
361 | public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
||
371 | |||
372 | |||
373 | /** |
||
374 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
375 | * @throws InvalidInterfaceException |
||
376 | * @throws InvalidDataTypeException |
||
377 | * @throws EE_Error |
||
378 | * @throws InvalidArgumentException |
||
379 | */ |
||
380 | public function get_total_line_items_with_no_transaction() |
||
384 | |||
385 | |||
386 | /** |
||
387 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
388 | * @throws InvalidInterfaceException |
||
389 | * @throws InvalidDataTypeException |
||
390 | * @throws EE_Error |
||
391 | * @throws InvalidArgumentException |
||
392 | */ |
||
393 | public function get_total_line_items_for_active_carts() |
||
397 | |||
398 | |||
399 | /** |
||
400 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
401 | * @throws InvalidInterfaceException |
||
402 | * @throws InvalidDataTypeException |
||
403 | * @throws EE_Error |
||
404 | * @throws InvalidArgumentException |
||
405 | */ |
||
406 | public function get_total_line_items_for_expired_carts() |
||
410 | |||
411 | |||
412 | /** |
||
413 | * Returns an array of grand total line items where the TXN_ID is 0. |
||
414 | * If $expired is set to true, then only line items for expired sessions will be returned. |
||
415 | * If $expired is set to false, then only line items for active sessions will be returned. |
||
416 | * |
||
417 | * @param null $expired |
||
418 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
419 | * @throws EE_Error |
||
420 | * @throws InvalidArgumentException |
||
421 | * @throws InvalidDataTypeException |
||
422 | * @throws InvalidInterfaceException |
||
423 | */ |
||
424 | private function get_total_line_items_for_carts($expired = null) |
||
442 | |||
443 | |||
444 | /** |
||
445 | * Returns an array of ticket total line items where the TXN_ID is 0 |
||
446 | * AND the timestamp is older than the session lifespan. |
||
447 | * |
||
448 | * @param int $timestamp |
||
449 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
450 | * @throws EE_Error |
||
451 | * @throws InvalidArgumentException |
||
452 | * @throws InvalidDataTypeException |
||
453 | * @throws InvalidInterfaceException |
||
454 | */ |
||
455 | public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
||
474 | } |
||
475 |
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.