/** * Adds the line item as a child to this line item * @param EE_Line_Item $line_item * @return void */ function add_child_line_item(EE_Line_Item $line_item) { if ($this->ID()) { $line_item->set_parent_ID($this->ID()); $line_item->save(); } else { $this->_Line_Item[$line_item->code()] = $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 EE_Line_Item $line_item * @return boolean success */ function add_child_line_item(EE_Line_Item $line_item) { 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->_Line_Item[$line_item->code()] = $line_item; return TRUE; } }
/** * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation. * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save() * However, if this line item is NOT saved to the DB, this just caches the parent on * the EE_Line_Item::_parent property. * @param EE_Line_Item $line_item * */ public function set_parent($line_item) { if ($this->ID()) { if (!$line_item->ID()) { $line_item->save(); } $this->set_parent_ID($line_item->ID()); $this->save(); } else { $this->_parent = $line_item; $this->set_parent_ID($line_item->ID()); } }