/** * Given the grand total line item and a ticket, finds the event sub-total * line item the ticket's purchase should be added onto * * @access public * @param EE_Line_Item $grand_total the grand total line item * @param EE_Ticket $ticket * @throws \EE_Error * @return EE_Line_Item */ public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { $first_datetime = $ticket->first_datetime(); if (!$first_datetime instanceof EE_Datetime) { throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID())); } $event = $first_datetime->event(); if (!$event instanceof EE_Event) { throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), $ticket->ID())); } $event_line_item = NULL; $found = false; foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { // default event subtotal, we should only ever find this the first time this method is called if (!$event_line_item->OBJ_ID()) { // let's use this! but first... set the event details EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); $found = true; break; } else { if ($event_line_item->OBJ_ID() === $event->ID()) { // found existing line item for this event in the cart, so break out of loop and use this one $found = true; break; } } } if (!$found) { //there is no event sub-total yet, so add it $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); // create a new "event" subtotal below that $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); // and set the event details EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); } return $event_line_item; }
/** * _total_ticket_quantity_within_event_additional_limit * * returns true if the requested ticket quantity * does not exceed the event's additional limit * when combined with the tickets for the same event * that have already been added to the cart * * @access protected * @param EE_Ticket $ticket * @param int $quantity * @param bool $cart_update * @return bool */ protected function _total_ticket_quantity_within_event_additional_limit(EE_Ticket $ticket, $quantity = 1, $cart_update = false) { $event = $ticket->first_datetime()->event(); // we want to exclude this ticket from the count if this is a cart update, // because we are not simply incrementing the cart count // but replacing the quantity in the cart with a totally new value $TKT_ID = $cart_update ? $ticket->ID() : 0; $event_tickets = $this->_event_tickets($TKT_ID); if (isset($event_tickets[$event->ID()])) { // add tickets that are already in cart $quantity += count($event_tickets[$event->ID()]); } return $quantity <= $event->additional_limit() ? true : false; }
/** * Given the grand total line item and a ticket, finds the event sub-total * line item the ticket's purchase should be added onto * * @access public * @param EE_Line_Item $grand_total the grand total line item * @param EE_Ticket $ticket * @throws \EE_Error * @return EE_Line_Item */ public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { $first_datetime = $ticket->first_datetime(); if (!$first_datetime instanceof EE_Datetime) { throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID())); } $event = $first_datetime->event(); if (!$event instanceof EE_Event) { throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), $ticket->ID())); } return EEH_Line_Item::get_event_line_item($grand_total, $event); }