1 | <?php |
||
28 | class EEM_Line_Item extends EEM_Base |
||
29 | { |
||
30 | |||
31 | /** |
||
32 | * Tax sub-total is just the total of all the taxes, which should be children |
||
33 | * of this line item. There should only ever be one tax sub-total, and it should |
||
34 | * be a direct child of. Its quantity and LIN_unit_price = 1. |
||
35 | */ |
||
36 | const type_tax_sub_total = 'tax-sub-total'; |
||
37 | |||
38 | /** |
||
39 | * Tax line items indicate a tax applied to all the taxable line items. |
||
40 | * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
||
41 | * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
||
42 | */ |
||
43 | const type_tax = 'tax'; |
||
44 | |||
45 | /** |
||
46 | * Indicating individual items purchased, or discounts or surcharges. |
||
47 | * The sum of all the regular line items plus the tax items should equal the grand total. |
||
48 | * Possible children are sub-line-items and cancellations. |
||
49 | * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
||
50 | * LIN_totals. Its LIN_percent = 0. |
||
51 | * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
||
52 | * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
||
53 | */ |
||
54 | const type_line_item = 'line-item'; |
||
55 | |||
56 | /** |
||
57 | * Line item indicating all the factors that make a single line item. |
||
58 | * Sub-line items should have NO children line items. |
||
59 | * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
||
60 | * contribution towards the price of ONE of their parent items, and its LIN_total should be |
||
61 | * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
||
62 | * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
||
63 | * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
||
64 | */ |
||
65 | const type_sub_line_item = 'sub-item'; |
||
66 | |||
67 | /** |
||
68 | * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
||
69 | * Direct children should be event subtotals. |
||
70 | * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
||
71 | */ |
||
72 | const type_sub_total = 'sub-total'; |
||
73 | |||
74 | /** |
||
75 | * Line item for the grand total of an order. |
||
76 | * Its direct children should be tax subtotals and (pre-tax) subtotals, |
||
77 | * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
||
78 | * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
||
79 | */ |
||
80 | const type_total = 'total'; |
||
81 | |||
82 | /** |
||
83 | * When a line item is cancelled, a sub-line-item of type 'cancellation' |
||
84 | * should be created, indicating the quantity that were cancelled |
||
85 | * (because a line item could have a quantity of 1, and its cancellation item |
||
86 | * could be for 3, indicating that originally 4 were purchased, but 3 have been |
||
87 | * cancelled, and only one remains). |
||
88 | * When items are refunded, a cancellation line item should be made, which points |
||
89 | * to teh payment model object which actually refunded the payment. |
||
90 | * Cancellations should NOT have any children line items; the should NOT affect |
||
91 | * any calculations, and are only meant as a record that cancellations have occurred. |
||
92 | * Their LIN_percent should be 0. |
||
93 | */ |
||
94 | const type_cancellation = 'cancellation'; |
||
95 | |||
96 | // various line item object types |
||
97 | const OBJ_TYPE_EVENT = 'Event'; |
||
98 | |||
99 | const OBJ_TYPE_PRICE = 'Price'; |
||
100 | |||
101 | const OBJ_TYPE_PROMOTION = 'Promotion'; |
||
102 | |||
103 | const OBJ_TYPE_TICKET = 'Ticket'; |
||
104 | |||
105 | const OBJ_TYPE_TRANSACTION = 'Transaction'; |
||
106 | |||
107 | /** |
||
108 | * @var EEM_Line_Item $_instance |
||
109 | */ |
||
110 | protected static $_instance; |
||
111 | |||
112 | |||
113 | /** |
||
114 | * private constructor to prevent direct creation |
||
115 | * |
||
116 | * @Constructor |
||
117 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
||
118 | * (and any incoming timezone data that gets saved). |
||
119 | * Note this just sends the timezone info to the date time model field objects. |
||
120 | * Default is NULL |
||
121 | * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
||
122 | * @throws EE_Error |
||
123 | * @throws InvalidArgumentException |
||
124 | */ |
||
125 | protected function __construct($timezone) |
||
256 | |||
257 | |||
258 | /** |
||
259 | * Gets all the line items for this transaction of the given type |
||
260 | * |
||
261 | * @param string $line_item_type like one of EEM_Line_Item::type_* |
||
262 | * @param EE_Transaction|int $transaction |
||
263 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
264 | * @throws EE_Error |
||
265 | * @throws InvalidArgumentException |
||
266 | * @throws InvalidDataTypeException |
||
267 | * @throws InvalidInterfaceException |
||
268 | */ |
||
269 | public function get_all_of_type_for_transaction($line_item_type, $transaction) |
||
279 | |||
280 | |||
281 | /** |
||
282 | * Gets all line items unrelated to tickets that are normal line items |
||
283 | * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
||
284 | * |
||
285 | * @param EE_Transaction|int $transaction |
||
286 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
287 | * @throws EE_Error |
||
288 | * @throws InvalidArgumentException |
||
289 | * @throws InvalidDataTypeException |
||
290 | * @throws InvalidInterfaceException |
||
291 | */ |
||
292 | public function get_all_non_ticket_line_items_for_transaction($transaction) |
||
306 | |||
307 | |||
308 | /** |
||
309 | * Deletes line items with no transaction who have passed the transaction cutoff time. |
||
310 | * This needs to be very efficient |
||
311 | * because if there are spam bots afoot there will be LOTS of line items |
||
312 | * |
||
313 | * @return int count of how many deleted |
||
314 | * @throws EE_Error |
||
315 | * @throws InvalidArgumentException |
||
316 | * @throws InvalidDataTypeException |
||
317 | * @throws InvalidInterfaceException |
||
318 | */ |
||
319 | public function delete_line_items_with_no_transaction() |
||
337 | |||
338 | |||
339 | /** |
||
340 | * get_line_item_for_transaction_object |
||
341 | * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
||
342 | * |
||
343 | * @param int $TXN_ID |
||
344 | * @param EE_Base_Class $object |
||
345 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
346 | * @throws EE_Error |
||
347 | * @throws InvalidArgumentException |
||
348 | * @throws InvalidDataTypeException |
||
349 | * @throws InvalidInterfaceException |
||
350 | * @throws ReflectionException |
||
351 | */ |
||
352 | public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
||
362 | |||
363 | |||
364 | /** |
||
365 | * get_object_line_items_for_transaction |
||
366 | * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
||
367 | * |
||
368 | * @param int $TXN_ID |
||
369 | * @param string $OBJ_type |
||
370 | * @param array $OBJ_IDs |
||
371 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
372 | * @throws EE_Error |
||
373 | */ |
||
374 | public function get_object_line_items_for_transaction( |
||
389 | |||
390 | |||
391 | /** |
||
392 | * get_all_ticket_line_items_for_transaction |
||
393 | * |
||
394 | * @param EE_Transaction $transaction |
||
395 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
396 | * @throws EE_Error |
||
397 | * @throws InvalidArgumentException |
||
398 | * @throws InvalidDataTypeException |
||
399 | * @throws InvalidInterfaceException |
||
400 | * @throws ReflectionException |
||
401 | */ |
||
402 | public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
||
411 | |||
412 | |||
413 | /** |
||
414 | * get_ticket_line_item_for_transaction |
||
415 | * |
||
416 | * @param int $TXN_ID |
||
417 | * @param int $TKT_ID |
||
418 | * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
||
419 | * @throws EE_Error |
||
420 | * @throws InvalidArgumentException |
||
421 | * @throws InvalidDataTypeException |
||
422 | * @throws InvalidInterfaceException |
||
423 | */ |
||
424 | public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
||
434 | |||
435 | |||
436 | /** |
||
437 | * get_existing_promotion_line_item |
||
438 | * searches the cart for existing line items for the specified promotion |
||
439 | * |
||
440 | * @since 1.0.0 |
||
441 | * @param EE_Line_Item $parent_line_item |
||
442 | * @param EE_Promotion $promotion |
||
443 | * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
||
444 | * @throws EE_Error |
||
445 | * @throws InvalidArgumentException |
||
446 | * @throws InvalidDataTypeException |
||
447 | * @throws InvalidInterfaceException |
||
448 | * @throws ReflectionException |
||
449 | */ |
||
450 | public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
||
461 | |||
462 | |||
463 | /** |
||
464 | * get_all_promotion_line_items |
||
465 | * searches the cart for any and all existing promotion line items |
||
466 | * |
||
467 | * @since 1.0.0 |
||
468 | * @param EE_Line_Item $parent_line_item |
||
469 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
470 | * @throws EE_Error |
||
471 | * @throws InvalidArgumentException |
||
472 | * @throws InvalidDataTypeException |
||
473 | * @throws InvalidInterfaceException |
||
474 | * @throws ReflectionException |
||
475 | */ |
||
476 | public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
||
486 | |||
487 | |||
488 | /** |
||
489 | * Gets the registration's corresponding line item. |
||
490 | * Note: basically does NOT support having multiple line items for a single ticket, |
||
491 | * which would happen if some of the registrations had a price modifier while others didn't. |
||
492 | * In order to support that, we'd probably need a LIN_ID on registrations or something. |
||
493 | * |
||
494 | * @param EE_Registration $registration |
||
495 | * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
||
496 | * @throws EE_Error |
||
497 | */ |
||
498 | public function get_line_item_for_registration(EE_Registration $registration) |
||
502 | |||
503 | |||
504 | /** |
||
505 | * Gets the query params used to retrieve a specific line item for the given registration |
||
506 | * |
||
507 | * @param EE_Registration $registration |
||
508 | * @param array $original_query_params any extra query params you'd like to be merged with |
||
509 | * @return array @see |
||
510 | * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
511 | * @throws EE_Error |
||
512 | */ |
||
513 | public function line_item_for_registration_query_params( |
||
525 | |||
526 | |||
527 | /** |
||
528 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
529 | * @throws InvalidInterfaceException |
||
530 | * @throws InvalidDataTypeException |
||
531 | * @throws EE_Error |
||
532 | * @throws InvalidArgumentException |
||
533 | */ |
||
534 | public function get_total_line_items_with_no_transaction() |
||
538 | |||
539 | |||
540 | /** |
||
541 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
542 | * @throws InvalidInterfaceException |
||
543 | * @throws InvalidDataTypeException |
||
544 | * @throws EE_Error |
||
545 | * @throws InvalidArgumentException |
||
546 | */ |
||
547 | public function get_total_line_items_for_active_carts() |
||
551 | |||
552 | |||
553 | /** |
||
554 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
555 | * @throws InvalidInterfaceException |
||
556 | * @throws InvalidDataTypeException |
||
557 | * @throws EE_Error |
||
558 | * @throws InvalidArgumentException |
||
559 | */ |
||
560 | public function get_total_line_items_for_expired_carts() |
||
564 | |||
565 | |||
566 | /** |
||
567 | * Returns an array of grand total line items where the TXN_ID is 0. |
||
568 | * If $expired is set to true, then only line items for expired sessions will be returned. |
||
569 | * If $expired is set to false, then only line items for active sessions will be returned. |
||
570 | * |
||
571 | * @param null $expired |
||
572 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
573 | * @throws EE_Error |
||
574 | * @throws InvalidArgumentException |
||
575 | * @throws InvalidDataTypeException |
||
576 | * @throws InvalidInterfaceException |
||
577 | */ |
||
578 | private function get_total_line_items_for_carts($expired = null) |
||
596 | |||
597 | |||
598 | /** |
||
599 | * Returns an array of ticket total line items where the TXN_ID is 0 |
||
600 | * AND the timestamp is older than the session lifespan. |
||
601 | * |
||
602 | * @param int $timestamp |
||
603 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
604 | * @throws EE_Error |
||
605 | * @throws InvalidArgumentException |
||
606 | * @throws InvalidDataTypeException |
||
607 | * @throws InvalidInterfaceException |
||
608 | */ |
||
609 | public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
||
628 | } |
||
629 |