/** * 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'))); }
/** * _payments_and_amount_owing_rows * * @param EE_Line_Item $line_item * @param array $options * @return mixed */ private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) { $html = ''; $owing = $line_item->total(); $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); if ($transaction instanceof EE_Transaction) { $registration_payments = array(); $registrations = !empty($options['registrations']) ? $options['registrations'] : $transaction->registrations(); foreach ($registrations as $registration) { if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { $registration_payments = $registration_payments + $registration->registration_payments(); } } if (!empty($registration_payments)) { foreach ($registration_payments as $registration_payment) { if ($registration_payment instanceof EE_Registration_Payment) { $owing = $owing - $registration_payment->amount(); $payment = $registration_payment->payment(); if ($payment instanceof EE_Payment) { $payment_desc = sprintf(__('Payment%1$s Received: %2$s', 'event_espresso'), $payment->txn_id_chq_nmbr() != '' ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' : '', $payment->timestamp()); } else { $payment_desc = ''; } // start of row $html .= EEH_HTML::tr('', '', 'total_tr odd'); // payment desc $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); // total td $html .= EEH_HTML::td(EEH_Template::format_currency($registration_payment->amount(), false, false), '', 'total jst-rght'); // end of row $html .= EEH_HTML::trx(); } } if ($line_item->total()) { // start of row $html .= EEH_HTML::tr('', '', 'total_tr odd'); // total td $html .= EEH_HTML::td(__('Amount Owing', 'event_espresso'), '', 'total_currency total jst-rght', '', ' colspan="3"'); // total td $html .= EEH_HTML::td(EEH_Template::format_currency($owing, false, false), '', 'total jst-rght'); // end of row $html .= EEH_HTML::trx(); } } } $this->_grand_total = $owing; return $html; }
/** * _payments_and_amount_owing_rows * * @param EE_Line_Item $line_item * @return mixed */ private function _payments_and_amount_owing_rows(EE_Line_Item $line_item) { $html = ''; $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); if ($transaction instanceof EE_Transaction) { $payments = $transaction->approved_payments(); if (!empty($payments)) { foreach ($payments as $payment) { if ($payment instanceof EE_Payment) { //$owing = $owing - $payment->amount(); $payment_desc = sprintf(__('Payment%1$s Received: %2$s', 'event_espresso'), $payment->txn_id_chq_nmbr() != '' ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' : '', $payment->timestamp()); // start of row $html .= EEH_HTML::tr('', '', 'total_tr odd'); // payment desc $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); // total td $html .= EEH_HTML::td(EEH_Template::format_currency($payment->amount(), false, false), '', 'total jst-rght'); // end of row $html .= EEH_HTML::trx(); } } //if ( $line_item->total() ) { // // start of row // $html .= EEH_HTML::tr( '', '', 'total_tr odd' ); // // total td // $html .= EEH_HTML::td( __('Amount Owing', 'event_espresso'), '', 'total_currency total jst-rght', '', ' colspan="3"' ); // // total td // $html .= EEH_HTML::td( EEH_Template::format_currency( $this->grand_total(), false, false ), '', 'total jst-rght' ); // // end of row // $html .= EEH_HTML::trx(); //} } } return $html; }
/** * 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; }
/** * Checks line item and children list $txn as their transaction. * Used by E_UnitTestCase_Test::test_new_typical_transaction() * @param EE_Transaction $txn * @param EE_Line_Item $line_item */ private function _ensure_txn_on_line_item_and_children($txn, $line_item) { $this->assertEquals($txn->ID(), $line_item->TXN_ID()); foreach ($line_item->children() as $child_line_item) { $this->_ensure_txn_on_line_item_and_children($txn, $child_line_item); } }