/** * Creates a new, unsaved line item, but if it's a ticket line item * with a total of 0, or a subtotal of 0, returns null instead * @param EEI_Line_Item $line_item * @param int $ticket_children * @return \EEI_Line_Item */ protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0) { if ($line_item->type() === EEM_Line_Item::type_sub_total && $ticket_children === 0) { return null; } return $line_item; }
/** * EE_Line_Item_Filter_Processor constructor. * @param \EE_Line_Item_Filter_Collection $line_item_filters * @param \EEI_Line_Item $grand_total_line_item * @throws \EE_Error */ public function __construct(EE_Line_Item_Filter_Collection $line_item_filters, EEI_Line_Item $grand_total_line_item) { $this->line_item_filters = $line_item_filters; if ($grand_total_line_item->type() !== EEM_Line_Item::type_total) { throw new EE_Error(__('A Line Item of the type total is required', 'event_espresso')); } $this->grand_total_line_item = $this->clone_and_reset_line_item_tree($grand_total_line_item); }
/** * Adjusts quantities for line items for tickets according to the registrations provided * in the constructor * @param EEI_Line_Item $line_item * @return EEI_Line_Item */ protected function _filter_billable_line_item(EEI_Line_Item $line_item) { // is this a ticket ? if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() == 'Ticket') { // if this ticket is billable at this moment, then we should have a positive quantity if (isset($this->_counts_per_line_item_code[$line_item->code()])) { // set quantity based on number of billable registrations for this ticket $quantity = $this->_counts_per_line_item_code[$line_item->code()]; } else { $quantity = 0; } $line_item->set_quantity($quantity); $line_item->set_total($line_item->unit_price() * $line_item->quantity()); } return $line_item; }
/** * Adds the line item as a child to this line item. If there is another child line * item with the same LIN_code, it is overwritten by this new one * @param EEI_Line_Item $line_item * @param bool $set_order * @return bool success * @throws \EE_Error */ function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) { // should we calculate the LIN_order for this line item ? if ($set_order || $line_item->order() === null) { $line_item->set_order(count($this->children())); } if ($this->ID()) { //check for any duplicate line items (with the same code), if so, this replaces it $line_item_with_same_code = $this->get_child_line_item($line_item->code()); if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { $this->delete_child_line_item($line_item_with_same_code->code()); } $line_item->set_parent_ID($this->ID()); if ($this->TXN_ID()) { $line_item->set_TXN_ID($this->TXN_ID()); } return $line_item->save(); } else { $this->_children[$line_item->code()] = $line_item; if ($line_item->parent() != $this) { $line_item->set_parent($this); } return TRUE; } }