Hi Tuan,
Following on from the
advice given in this post....
I've been able to set prices for all events that involve tickets for adults and children.
I also added two custom fields, and used fee formulas to calculate the charges. All good.
In order to keep it simple for the site administrators, I wanted a way of being able to change the prices of the tickets, without having to add (and apply) different custom fields to each event with a varying price.
The way I got around this was to add another tag into the
Fee Formula. So instead of fixing the price with
'[FIELD VALUE]*20', I've been able to use
'[FIELD VALUE]*{adult_price}', where
adult_price is the name of the Extra Information field in each event.
The code I had to change was in:
/administrator/components/com_eventbooking/libraries/rad/form/form.php
I've attached a patched file.
...and it looks something like this (replacing lines 259-260):
Code:
//The original two lines are below
$formula = $field->row->fee_formula;
$formula = str_replace('[FIELD_VALUE]', floatval($field->value), $formula);
// This part checks the fee formula for a numeric multiplier (ie. [FEE_VALUE*5.00])
$multiplier = '';
preg_match('#\{(.*?)\}#', $formula, $match);
$multiplier = $match[1];
// Obtain EventID from the REFERER URL
$url = ($_SERVER['HTTP_REFERER']);
$query = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY);
$params = array();
parse_str($query, $params);
// Set the event ID
if (isset($params['event_id'])) {
$event_id = ($params['event_id']);
} else {
// If not part of the referer URL, get the query string on first page load.
$event_id = ($_GET['event_id']);
}
// If the formula contains no numbers (ie. text in curly brackets, {adult_price}) - work out the fee multiplier
if((!empty($multiplier)) && (isset($event_id))) {
$db = JFactory::getDbo();
$sql = 'SELECT custom_fields FROM #__eb_events WHERE id=' . $event_id;
$db->setQuery($sql);
$custom_field = $db->loadResult();
$params = new JRegistry($custom_field);
$formula = str_replace('{' . $multiplier . '}', $params[$multiplier], $formula);
}
What I wanted to ask was if you knew of a better way of doing this (perhaps with a plugin)?
If you had any advice - it would be much appreciated. Especially if there was a way to achieve the same thing without editing the core component files.
In the meantime - thanks for a great product!