Please post all pre-sales questions of all products on this forum

Fee Formula based on Extra Information field value

  • Chiddingfold Cinema
  • Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 7 months ago - 9 years 7 months ago #51117 by Chiddingfold Cinema
Fee Formula based on Extra Information field value was created by Chiddingfold Cinema
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!
Last edit: 9 years 7 months ago by Chiddingfold Cinema. Reason: Missed the rather crucial altered formula off the code!

Please Log in or Create an account to join the conversation.

More
9 years 7 months ago #51135 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Fee Formula based on Extra Information field value
Hi

The solution you are using is correct. And I agree that will simpler the work of site administrator for setting up the custom field.

At the moment, we don't have a way to do that without customizing code, so you still have to customize the code as how you are doing at the moment.

Tuan
The following user(s) said Thank You: Chiddingfold Cinema

Please Log in or Create an account to join the conversation.

Moderators: Tuan Pham NgocGiang Dinh TruongMr. Dam