/** * Returns the new line item created by adding a purchase of the ticket * @param \EE_Line_Item $total_line_item * @param EE_Ticket $ticket * @param int $qty * @return \EE_Line_Item * @throws \EE_Error */ public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { $line_item = null; if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { $tickets_subtotal_line_item = $total_line_item->get_child_line_item('tickets'); if ($tickets_subtotal_line_item instanceof EE_Line_Item && $tickets_subtotal_line_item->is_sub_total()) { $ticket_line_items = $total_line_item->get_child_line_item('tickets')->children(); foreach ((array) $ticket_line_items as $ticket_line_item) { if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_ID() == $ticket->ID()) { $line_item = $ticket_line_item; break; } } } } if ($line_item instanceof EE_Line_Item) { $qty += $line_item->quantity(); $line_item->set_quantity($qty); $line_item->set_total($line_item->unit_price() * $qty); $line_item->save(); return $line_item; } return null; }
/** * Returns the new line item created by adding a purchase of the ticket * @param \EE_Line_Item $total_line_item * @param EE_Ticket $ticket * @param int $qty * @return \EE_Line_Item * @throws \EE_Error */ public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { $line_item = null; if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); foreach ((array) $ticket_line_items as $ticket_line_item) { if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_ID() == $ticket->ID()) { $line_item = $ticket_line_item; break; } } } if ($line_item instanceof EE_Line_Item) { EEH_Line_Item::increment_quantity($line_item, $qty); return $line_item; } return null; }