/** * get_all_promotion_line_items * searches the cart for any and all existing promotion line items * * @since 1.0.0 * * @param EE_Line_Item $parent_line_item * @return EE_Line_Item[] */ public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) { return $this->get_all(array(array('TXN_ID' => $parent_line_item->TXN_ID(), 'LIN_parent' => $parent_line_item->ID(), 'OBJ_type' => 'Promotion'))); }
/** * get_redeemable_scope_promos * searches the cart for any items that this promotion applies to * * @since 1.0.0 * * @param EE_Line_Item $parent_line_item the line item to create the new promotion line item under * @param EE_Promotion $promotion the promotion object that the line item is being created for * @param string $promo_name * @param bool $affects_tax * @return \EE_Line_Item * @throws \EE_Error */ public function generate_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion, $promo_name = '', $affects_tax = false) { // verify EE_Line_Item if (!$parent_line_item instanceof EE_Line_Item) { throw new EE_Error(__('A valid EE_Line_Item object is required to generate a promotion line item.', 'event_espresso')); } // verify EE_Promotion if (!$promotion instanceof EE_Promotion) { throw new EE_Error(__('A valid EE_Promotion object is required to generate a promotion line item.', 'event_espresso')); } $promo_name = !empty($promo_name) ? $promo_name : $promotion->name(); $promo_desc = $promotion->price()->desc(); $promo_desc .= $promotion->code() != '' ? ' ( ' . $promotion->code() . ' )' : ''; // generate promotion line_item $line_item = EE_Line_Item::new_instance(array('LIN_code' => 'promotion-' . $promotion->ID(), 'TXN_ID' => $parent_line_item->TXN_ID(), 'LIN_name' => apply_filters('FHEE__EE_Promotion_Scope__generate_promotion_line_item__LIN_name', $promo_name, $promotion), 'LIN_desc' => $promo_desc, 'LIN_unit_price' => $promotion->is_percent() ? 0 : $promotion->amount(), 'LIN_percent' => $promotion->is_percent() ? $promotion->amount() : 0, 'LIN_is_taxable' => $affects_tax, 'LIN_order' => $promotion->price()->order() + EE_Promotion_Scope::$_counter, 'LIN_total' => $promotion->calculated_amount_on_value($parent_line_item->total()), 'LIN_quantity' => 1, 'LIN_parent' => $parent_line_item->ID(), 'LIN_type' => $this->get_promotion_line_item_type(), 'OBJ_ID' => $promotion->ID(), 'OBJ_type' => 'Promotion')); EE_Promotion_Scope::$_counter++; return $line_item; }
/** * generate_ONE_registration_from_line_item * * Although a ticket line item may have a quantity greater than 1, * this method will ONLY CREATE ONE REGISTRATION !!! * Regardless of the ticket line item quantity. * This means that any code calling this method is responsible for ensuring * that the final registration count matches the ticket line item quantity. * This was done to make it easier to match the number of registrations * to the number of tickets in the cart, when the cart has been edited * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. * * @param EE_Line_Item $line_item * @param \EE_Transaction $transaction * @param int $att_nmbr * @param int $total_ticket_count * @return \EE_Registration | null * @throws \EE_Error */ public function generate_ONE_registration_from_line_item(EE_Line_Item $line_item, EE_Transaction $transaction, $att_nmbr = 1, $total_ticket_count = 1) { // grab the related ticket object for this line_item $ticket = $line_item->ticket(); if (!$ticket instanceof EE_Ticket) { EE_Error::add_error(sprintf(__("Line item %s did not contain a valid ticket", "event_espresso"), $line_item->ID()), __FILE__, __FUNCTION__, __LINE__); return null; } $first_datetime = $ticket->get_first_related('Datetime'); if (!$first_datetime instanceof EE_Datetime) { EE_Error::add_error(sprintf(__("The ticket (%s) is not associated with any valid datetimes.", "event_espresso"), $ticket->name()), __FILE__, __FUNCTION__, __LINE__); return null; } $event = $first_datetime->get_first_related('Event'); if (!$event instanceof EE_Event) { EE_Error::add_error(sprintf(__("The ticket (%s) is not associated with a valid event.", "event_espresso"), $ticket->name()), __FILE__, __FUNCTION__, __LINE__); return null; } $reg_url_link = $this->generate_reg_url_link($att_nmbr, $line_item); if ($this->_reg_final_price_per_tkt_line_item === null) { $this->_reg_final_price_per_tkt_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item()); } //ok now find this new registration's final price if (isset($this->_reg_final_price_per_tkt_line_item[$line_item->ID()])) { $final_price = $this->_reg_final_price_per_tkt_line_item[$line_item->ID()]; } else { $message = sprintf(__('The ticket line item (ID:%1$d) had no entry in the reg_final_price_per_tkt_line_item array.', 'event_espresso'), $line_item->ID()); if (WP_DEBUG) { throw new EE_Error($message); } else { EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); } $final_price = $ticket->get_ticket_total_with_taxes(); } // now create a new registration for the ticket $registration = EE_Registration::new_instance(array('EVT_ID' => $event->ID(), 'TXN_ID' => $transaction->ID(), 'TKT_ID' => $ticket->ID(), 'STS_ID' => EEM_Registration::status_id_incomplete, 'REG_date' => $transaction->datetime(), 'REG_final_price' => $final_price, 'REG_session' => EE_Registry::instance()->SSN->id(), 'REG_count' => $att_nmbr, 'REG_group_size' => $total_ticket_count, 'REG_url_link' => $reg_url_link)); $registration->set_reg_code($this->generate_reg_code($registration)); $registration->save(); $registration->_add_relation_to($event, 'Event', array(), $event->ID()); $registration->_add_relation_to($line_item->ticket(), 'Ticket', array(), $line_item->ticket()->ID()); $transaction->_add_relation_to($registration, 'Registration'); return $registration; }
/** * _delete_line_item * * @access public * @param \EE_Line_Item $line_item * @return boolean */ public static function _delete_line_item(EE_Line_Item $line_item) { if ($line_item->ID()) { return $line_item->delete(); } else { return EE_Registry::instance()->CART->delete_items($line_item->code()); } }
/** * generate_ONE_registration_from_line_item * * Although a ticket line item may have a quantity greater than 1, * this method will ONLY CREATE ONE REGISTRATION !!! * Regardless of the ticket line item quantity. * This means that any code calling this method is responsible for ensuring * that the final registration count matches the ticket line item quantity. * This was done to make it easier to match the number of registrations * to the number of tickets in the cart, when the cart has been edited * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. * * @param EE_Line_Item $line_item * @param \EE_Transaction $transaction * @param int $att_nmbr * @param int $total_ticket_count * @return \EE_Registration | null * @throws \EE_Error */ public function generate_ONE_registration_from_line_item(EE_Line_Item $line_item, EE_Transaction $transaction, $att_nmbr = 1, $total_ticket_count = 1) { // grab the related ticket object for this line_item $ticket = $line_item->ticket(); if (!$ticket instanceof EE_Ticket) { EE_Error::add_error(sprintf(__("Line item %s did not contain a valid ticket", "event_espresso"), $line_item->ID()), __FILE__, __FUNCTION__, __LINE__); return null; } $first_datetime = $ticket->get_first_related('Datetime'); if (!$first_datetime instanceof EE_Datetime) { EE_Error::add_error(sprintf(__("The ticket (%s) is not associated with any valid datetimes.", "event_espresso"), $ticket->name()), __FILE__, __FUNCTION__, __LINE__); return null; } $event = $first_datetime->get_first_related('Event'); if (!$event instanceof EE_Event) { EE_Error::add_error(sprintf(__("The ticket (%s) is not associated with a valid event.", "event_espresso"), $ticket->name()), __FILE__, __FUNCTION__, __LINE__); return null; } $reg_url_link = $this->generate_reg_url_link($att_nmbr, $line_item); // now create a new registration for the ticket $registration = EE_Registration::new_instance(array('EVT_ID' => $event->ID(), 'TXN_ID' => $transaction->ID(), 'TKT_ID' => $ticket->ID(), 'STS_ID' => EEM_Registration::status_id_incomplete, 'REG_date' => $transaction->datetime(), 'REG_final_price' => $ticket->get_ticket_total_with_taxes(), 'REG_session' => EE_Registry::instance()->SSN->id(), 'REG_count' => $att_nmbr, 'REG_group_size' => $total_ticket_count, 'REG_url_link' => $reg_url_link)); $registration->set_reg_code($this->generate_reg_code($registration)); $registration->save(); $registration->_add_relation_to($event, 'Event', array(), $event->ID()); $registration->_add_relation_to($line_item->ticket(), 'Ticket', array(), $line_item->ticket()->ID()); $transaction->_add_relation_to($registration, 'Registration'); return $registration; }
/** * _total_row * * @param EE_Line_Item $line_item * @param string $text * @param int $total_items * @return mixed */ private function _total_row(EE_Line_Item $line_item, $text = '', $total_items = 0) { //EE_Registry::instance()->load_helper('Money'); // start of row $html = EEH_HTML::tr('', 'event-cart-total-row-' . $line_item->ID(), 'event-cart-total-row-' . $line_item->type() . ' event-cart-total-row total_tr'); // total td $html .= EEH_HTML::td(EEH_HTML::strong($text), '', 'total_currency total jst-rght', '', ' colspan="2"'); // total qty $total_items = $total_items ? $total_items : ''; $html .= EEH_HTML::td(EEH_HTML::strong('<span class="total">' . $total_items . '</span>'), '', 'total jst-cntr'); // total td $html .= EEH_HTML::td(EEH_HTML::strong($line_item->total_no_code()), '', 'total jst-rght'); // end of row $html .= EEH_HTML::trx(); return $html; }
/** * Prints out a representation of the line item tree * @param EE_Line_Item $line_item * @param int $indentation * @return void */ public static function visualize(EE_Line_Item $line_item, $indentation = 0) { echo "\n<br />"; for ($i = 0; $i < $indentation; $i++) { echo " - "; } if ($line_item->is_percent()) { $breakdown = $line_item->percent() . '%'; } else { $breakdown = '$' . $line_item->unit_price() . "x" . $line_item->quantity(); } echo $line_item->name() . "( " . $line_item->ID() . " ) : " . $line_item->type() . " \$" . $line_item->total() . "(" . $breakdown . ")"; if ($line_item->is_taxable()) { echo " * taxable"; } if ($line_item->children()) { foreach ($line_item->children() as $child) { self::visualize($child, $indentation + 1); } } }
/** * 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()); } }