/** * 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); }
/** * Verifies that we don't re-add shipping if it's already been added * @group 4710 */ public function test_set_redirect_info__with_promotion() { $ppm = $this->new_model_obj_with_dependencies('Payment_Method', array('PMD_type' => 'Paypal_Standard')); $ppg = $ppm->type_obj()->get_gateway(); $ppg->set_settings($this->_test_settings); $t = $this->new_typical_transaction(array('ticket_types' => 2)); $event = EEM_Event::instance()->get_one(array(array('Registration.TXN_ID' => $t->ID()))); $event_li = EEH_Line_Item::get_event_line_item($t->total_line_item(), $event); $discount_li = $this->new_model_obj_with_dependencies('Line_Item', array('LIN_parent' => $event_li->ID(), 'LIN_name' => 'discount', 'LIN_code' => 'discount', 'LIN_unit_price' => -10, 'LIN_quantity' => 1, 'LIN_percent' => 0, 'LIN_type' => EEM_Line_Item::type_line_item, 'LIN_is_taxable' => false, 'TXN_ID' => $t->ID())); $t->total_line_item()->recalculate_total_including_taxes(); $p = $this->new_model_obj_with_dependencies('Payment', array('TXN_ID' => $t->ID(), 'PMD_ID' => $ppm->ID(), 'PAY_amount' => $t->total())); $this->assertNotEquals(EEM_Payment::status_id_approved, $p->status()); $p = $ppg->set_redirection_info($p, NULL, self::return_url, self::notify_url, self::cancel_url); $rargs = $p->redirect_args(); //also check we DID enumerat ethe line items $this->assertEquals('10', $rargs['discount_amount_cart']); $this->assertTrue(isset($rargs['item_name_1'])); $this->assertTrue(isset($rargs['amount_1'])); //although we shouldn't be mentioning how much taxes are per item. leave that to paypal $this->assertFalse(isset($rargs['tax_1'])); $this->assertTrue(isset($rargs['item_name_2'])); $this->assertTrue(isset($rargs['amount_2'])); $this->assertTrue(isset($rargs['quantity_2'])); $this->assertFalse(isset($rargs['tax_2'])); }