function calculate_cart_totals_process($refresh = true, $refresh_curr_data = true) { global $event_details, $epl_current_step, $event_totals, $cart_totals, $hide_offline_payment_options; //$db = debug_backtrace(); //echo "<pre class='prettyprint'>" . __LINE__ . "> calculate_cart_totals " . print_r( $db[0]['line'] . '>>' . $db[0]['file'], true ) . "</pre>"; if (!$refresh && !epl_is_empty_array($event_totals)) { return $event_totals; } if (!$refresh && ($data = wp_cache_get('cart_totals_' . $this->get_current_event_id())) !== false) { $event_totals = $data; return $data; } $_discount_steps = array('process_cart_action', 'regis_form'); $is_discountable_step = in_array($epl_current_step, $_discount_steps); //need this check for waitlist record otherwise the whole cart //total will be assigned to the waitlist registration //if uncomment this line, discount will get overwritten in show cart overview //if ( !$refresh ) { if ((!in_array($epl_current_step, $_discount_steps) || in_array($epl_current_step, $_discount_steps) && !$_POST) && isset($this->current_data[$this->regis_id]['cart_totals']['money_totals'])) { $data = $this->current_data[$this->regis_id]['_events'][$this->get_current_event_id()]; $cart_totals = $this->current_data[$this->regis_id]['cart_totals']; wp_cache_set('cart_totals', $cart_totals); $event_totals = $data; return $cart_totals; } //} $this->discountable_step = true; $this->ecm->setup_event_details($this->get_current_event_id()); $events = (array) $this->get_events_in_cart(); if (empty($events)) { return $this->epl_util->epl_invoke_error(20); } if (isset($_REQUEST['alt_total']) && $_REQUEST['alt_total'] == '') { unset($this->current_data[$this->regis_id]['alt_total']); } if (isset($_REQUEST['_epl_donation_amount']) && $_REQUEST['_epl_donation_amount'] == '') { unset($this->current_data[$this->regis_id]['_epl_donation_amount']); } $price_multiplier = 1; $pay_deposit_now = $_POST && $is_discountable_step ? epl_get_element('_epl_pay_deposit', $_POST, 0) : epl_get_element_m('pay_deposit', 'money_totals', $this->current_data[$this->regis_id]['cart_totals'], 0); if ($pay_deposit_now == 1) { $hide_offline_payment_options = true; } $cart_totals = array('money_totals' => array(), '_att_quantity' => array()); $cart_totals['money_totals']['grand_total'] = 0; $cart_totals['money_totals']['min_deposit'] = 0; $cart_totals['money_totals']['pay_deposit'] = $pay_deposit_now; $cart_totals['money_totals']['subtotal'] = 0; $cart_totals['money_totals']['surcharge'] = 0; $cart_totals['money_totals']['discountable_total'] = 0; $cart_totals['money_totals']['non_discountable_total'] = 0; $cart_totals['money_totals']['donation_amount'] = 0; $cart_totals['_att_quantity']['total'] = 0; $cart_totals['_att_quantity']['total_n'] = 0; $cart_totals['_att_quantity']['total_non_disc'] = 0; $cart_totals['money_totals']['num_events_in_cart'] = epl_get_num_events_in_cart(); $cart_totals['money_totals']['num_discountable_events_in_cart'] = epl_get_num_events_in_cart(); //for each event in the cart foreach ($events as $event_id => $val) { if (!is_int($event_id)) { continue; } setup_event_details($event_id); $surcharge_after_discount = epl_get_element('_epl_surcharge_before_discount', $event_details, 0) == 0; //not to everride other events in the cart if (!empty($_REQUEST['event_id']) && $_REQUEST['event_id'] != $event_id || isset($_REQUEST['epl_m']) || epl_get_element('caller', $_REQUEST) == 'summary') { $data[$event_id] = $this->current_data[$this->regis_id]['_events'][$event_id]; if (isset($data[$event_id]['money_totals'])) { $cart_totals['money_totals']['grand_total'] += $data[$event_id]['money_totals']['grand_total']; $cart_totals['money_totals']['min_deposit'] = epl_get_element_m('min_deposit', 'money_totals', $this->current_data[$this->regis_id]['cart_totals']); $cart_totals['money_totals']['subtotal'] += $data[$event_id]['money_totals']['subtotal']; $cart_totals['money_totals']['surcharge'] += $data[$event_id]['money_totals']['surcharge']; $cart_totals['money_totals']['discountable_total'] += $data[$event_id]['money_totals']['discountable_total']; $cart_totals['money_totals']['non_discountable_total'] += $data[$event_id]['money_totals']['non_discountable_total']; $cart_totals['_att_quantity']['total'] += $data[$event_id]['_att_quantity']['total'][$event_id]; $cart_totals['_att_quantity']['total_n'] += $data[$event_id]['_att_quantity']['total_n'][$event_id]; $cart_totals['_att_quantity']['total_non_disc'] += $data[$event_id]['_att_quantity']['total_non_disc'][$event_id]; } continue; } else { //echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r($event_id, true). "</pre>"; $_allow_glob_disc = epl_get_element('_epl_allow_global_discounts', $event_details, 0) == 10; //$has_event_level_disc = array_sum($event_details['_epl_discount_active']) > 0; //number of dates in the cart for this event. $dates = isset($this->current_data[$this->regis_id]['_dates']['_epl_start_date'][$event_id]) ? $this->current_data[$this->regis_id]['_dates']['_epl_start_date'][$event_id] : array(); $num_days_in_cart = count($dates); //if price per date $price_multiplier = $event_details['_epl_price_per'] == 10 ? $num_days_in_cart : 1; $_total_qty = 0; $_total_n_qty = 0; $_total_non_disc_qty = 0; if (!is_null($this->get_att_quantity_values())) { //attendee quantities in the cart for this event $att_qty = epl_get_element($event_id, $this->current_data[$this->regis_id]['_dates']['_att_quantity']); //echo "<pre class='prettyprint'>" . __LINE__ . "> $event_id >>> " . print_r($att_qty, true). "</pre>"; //total attendees for the event $day_total = array_sum((array) $att_qty); //$data[$event_id] = array( ); $data[$event_id]['money_totals'] = array(); $data[$event_id]['money_totals']['grand_total'] = 0; $data[$event_id]['money_totals']['min_deposit'] = 0; $data[$event_id]['money_totals']['subtotal'] = 0; $data[$event_id]['money_totals']['surcharge'] = 0; $data[$event_id]['money_totals']['discountable_total'] = 0; $data[$event_id]['money_totals']['non_discountable_total'] = 0; $data[$event_id]['_att_quantity']['total'][$event_id] = 0; $_price = 0; $prices = $this->get_event_property('_epl_price'); $member_prices = $this->get_event_property('_epl_member_price'); //price covers event or per date $price_per = epl_nz($this->get_event_property('_epl_price_per'), 10); foreach ((array) $att_qty as $price_id => $price_qty) { $_type = epl_get_element($price_id, epl_get_element('_epl_price_type', $event_details), 'att'); $_disc = epl_get_element($price_id, epl_get_element('_epl_price_discountable', $event_details), 10); //echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r( $_disc, true ) . "</pre>"; //if ( epl_get_element( $price_id, epl_get_element( '_epl_price_type', $event_details ), 'att' ) == 'att' ) { //if array, if (is_array($price_qty)) { $_qty = array_sum($price_qty); if (epl_is_date_level_price()) { $price_multiplier = 1; } } else { $_qty = $price_qty; } $_price = (int) $_qty * epl_nz(epl_get_element($price_id, $prices), 0); if (isset($member_prices[$price_id]) && $member_prices[$price_id] != '' && is_user_logged_in()) { $_price = (int) $_qty * epl_nz(epl_get_element($price_id, $member_prices), 0); } if ($_type == 'att') { $_total_qty += $_qty; } else { $_total_n_qty += $_qty; } $data[$event_id]['money_totals']['subtotal'] += $_price; $_tmpsurcharge = array('total' => $_price, 'price_id' => $price_id, 'qty' => $_qty); $_tmpsurcharge = $this->process_price_surcharge($_tmpsurcharge); $_tmpsurcharge['surcharge'] = epl_get_element('surcharge', $_tmpsurcharge, 0); if ($_tmpsurcharge['surcharge'] > 0) { $data[$event_id]['money_totals']['surcharge'] += epl_get_element('surcharge', $_tmpsurcharge, 0); $_price += $_tmpsurcharge['surcharge']; } $data[$event_id]['_att_quantity'][$price_id] = $_qty; $data[$event_id]['money_totals'][$price_id] = $_price; if ($_disc == 0) { $data[$event_id]['money_totals']['non_discountable_total'] += $_price; if ($_qty > 0) { $_total_non_disc_qty += $_qty; } } else { $data[$event_id]['money_totals']['discountable_total'] += $_price; } $data[$event_id]['money_totals']['grand_total'] += $_price; //} } } epl_get_element('discountable_total', $data[$event_id]['money_totals']) ? $data[$event_id]['money_totals']['discountable_total'] *= $price_multiplier : null; $data[$event_id]['money_totals']['grand_total'] *= $price_multiplier; if ($price_per == 10) { $data[$event_id]['money_totals']['subtotal'] = $data[$event_id]['money_totals']['grand_total']; } $data[$event_id]['_att_quantity']['total'][$event_id] = $_total_qty; $data[$event_id]['_att_quantity']['total_n'][$event_id] = $_total_n_qty; $data[$event_id]['_att_quantity']['total_non_disc'][$event_id] = $_total_non_disc_qty; $data[$event_id] = $this->process_event_surcharge($data[$event_id], 'before_discount'); //epl_debug_message( basename( __FILE__ ) . '(' . __LINE__ . ')', $data[$event_id] ); //if ( epl_sc_is_enabled() && epl_get_num_events_in_cart() > 1 ) // $data[$event_id] = $this->edm->process_discount( $data[$event_id] ); if (!$surcharge_after_discount) { $data[$event_id] = $this->process_event_surcharge($data[$event_id], 'after_discount'); } //epl_debug_message( basename( __FILE__ ) . '(' . __LINE__ . ')', $data[$event_id] ); $cart_totals['money_totals']['grand_total'] += $data[$event_id]['money_totals']['grand_total']; $cart_totals['money_totals']['min_deposit'] += $this->calculate_deposit($data[$event_id]['money_totals']['grand_total']); $cart_totals['money_totals']['surcharge'] += $data[$event_id]['money_totals']['surcharge']; $cart_totals['money_totals']['subtotal'] += $data[$event_id]['money_totals']['subtotal']; $cart_totals['money_totals']['discountable_total'] += $data[$event_id]['money_totals']['discountable_total']; $cart_totals['money_totals']['non_discountable_total'] += $data[$event_id]['money_totals']['non_discountable_total']; $cart_totals['_att_quantity']['total'] += $data[$event_id]['_att_quantity']['total'][$event_id]; $cart_totals['_att_quantity']['total_n'] += $data[$event_id]['_att_quantity']['total_n'][$event_id]; $cart_totals['_att_quantity']['total_non_disc'] += $data[$event_id]['_att_quantity']['total_non_disc'][$event_id]; //if($surcharge_after_discount) // $cart_totals['money_totals']['discountable_total'] += $cart_totals['money_totals']['surcharge']; if (!$_allow_glob_disc) { $cart_totals['money_totals']['num_discountable_events_in_cart']--; } } } //epl_debug_message( basename( __FILE__ ) . '(' . __LINE__ . ')', $data ); $event_totals = $data; //$cart_totals = $this->process_cart_surcharge( $cart_totals, 'before_discount' ); if ($this->discountable_step) { $cart_totals = $this->process_pay_profile_disc($cart_totals); $cart_totals = $this->edm->process_discount($cart_totals); } $cart_totals = $this->process_cart_surcharge($cart_totals, 'after_discount'); $this->current_data[$this->regis_id]['_events'] = $data; if (($donation = epl_get_element_m('_epl_donation_amount', $this->regis_id, $this->get_current_data(), '')) != '') { $donation = abs($donation); $cart_totals['money_totals']['donation_amount'] = $donation; $cart_totals['money_totals']['grand_total'] += $donation; } if (($alt_total = epl_get_element_m('alt_total', $this->regis_id, $this->get_current_data(), '')) != '') { $cart_totals['money_totals']['original_total'] = $cart_totals['money_totals']['grand_total']; $cart_totals['money_totals']['grand_total'] = $alt_total; } wp_cache_set('cart_totals', $data); $this->current_data[$this->regis_id]['cart_totals'] = $cart_totals; $this->epl->epl_util->set_response_param('total_due', $cart_totals['money_totals']['grand_total']); $this->epl->epl_util->set_response_param('hide_offline_payment_options', $hide_offline_payment_options); if ($refresh_curr_data) { $this->refresh_data(); } return $data; }
<div id="epl_main_container" class="<?php echo $mode; ?> "> <?php if (epl_get_num_events_in_cart() == 0) { ?> <div class="epl_info"><?php epl_e('Your event cart is empty.'); ?> </div> <?php } else { ?> <?php if (isset($cart_data['message'])) { ?> <div class="epl_error"><?php echo $cart_data['message']; ?> </div> <?php return; } ?> <div id="epl_ajax_content">