$numberRegistrants * Custom Field

More
11 years 4 months ago - 11 years 4 months ago #52924 by mikek
$numberRegistrants * Custom Field was created by mikek
Hi Tuan,
Using version 1.6.6
Is there a way to use a custom field and fee formula to multiply by the Number of Registrants entered?
Something like this:
Code:
50 * ($numberRegistrants * [FIELD_VALUE])
I know that doesn't work, but it will do the math, because this works: 50 * (2 * [FIELD_VALUE])

I just need 1 custom field per event, but it needs to multiply by the number_registered input box. Surely this can be done, right?
Basically a Depend On option for the Number Registrants input field.

I've heavily modified this component and understand the code. So I'm able to make major code changes if you can guide me.

Thanks,
Mike
Last edit: 11 years 4 months ago by mikek.

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
11 years 4 months ago - 11 years 4 months ago #52966 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic $numberRegistrants * Custom Field
Hi Mike

Unfortunately, it is not possible to use that [NUMBER_REGISTRANT] tag in the fee formula. Since you customized the extension heavily, I think you understand the code quite well, so I will give you my ideas to make it works with that tag:

1. As you see, that fee is calculated in the calculateFee method of RADForm class administrator/com_eventbooking/libraries/rad/form/form.php

2. To make it possible to use number registrant in the formula, we will need to find a way to pass it to the calculateFee method. Maybe pass it as as a parameter of the method ? In this case, I think you can modify code alitle:

public function calculateFee()

To

public function calculateFee($numberRegistrants = 1)

$formula = str_replace('[NUMBER_REGISTRANTS]', $numberRegistrants , $formula);

Something like that. Then you can use [NUMBER_REGISTRANTS] tag in fee calculation

3. Now, everywhere you call $form->calculateFee(), you should check and pass the correct $numberRegistrants to that method call

That's just my idea. Hope it give you alitle help

Tuan
Last edit: 11 years 4 months ago by Tuan Pham Ngoc.

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

More
11 years 4 months ago #52996 by mikek
Replied by mikek on topic $numberRegistrants * Custom Field
Thanks for the reply Tuan. It makes sense what you suggested but it's not what I need. I only need to get the value of number_registrants so I can multiply by it.
I started making your changes and then realized I don't need to change the [FIELD_VALUE] because I still want it to work based on my 1 custom fee field.
I need to be able to do a more complex multiplication within the fee formula by getting the value of $numberRegistrants. But I can't get the value! It must be available on the form.php page but I can't pull it out of the arrays. I've tried many things to get the value from the form.php page, but nothing returns the number.
Can you maybe pull it out of the array like this? $numRegistrants = $field->row->numberRegistrants->value;

This is the string that will work in form.php, if we can get a value for $numberRegistrants.
Code:
$formula = str_replace('[FIELD_VALUE]', floatval(($field->value) * $numberRegistrants), $formula);

This is something I need to make work. I know it can be done.
How can I get the value of number_registrants?
We know the value is available on the page, but how do I get it?
Ajax is storing the value somewhere, we need to get it out.

Thanks for your help!!

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
11 years 4 months ago #53010 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic $numberRegistrants * Custom Field
Hi

You can try this code:
Code:
$session = JFactory::getSession(); $numberRegistrants = (int) $session->get('eb_number_registrants', ''); if (!$numberRegistrants) { $numberRegistrants = 1; }

Something like that. However, please note that the calculateFee method is called on different places, so please test all the cases to make sure the modification you made works

Tuan

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

More
11 years 4 months ago #53029 by mikek
Replied by mikek on topic $numberRegistrants * Custom Field
Alright, I finally figured it out!! Took me 2 days, but I got it.
I think this is a feature that should be included. It's especially useful because it allows for Everything to run through Group Registration, even for 1 person. If there is only 1 registrant, then all your custom fields multiply by 1, keeping the price right for just 1 person...BUT with the new code if you have 2 or more registrants then your custom fields are multiplied by 2, 3, 4, ect...
Maybe it could be taken one step further and add a depend on field to it, so you could assigned it to different custom fields.
It works Great and is very useful.

Here are the changes to the code:
Step 1: Change the [2] to a [1] in the file "components/com_eventbooking/views/register/tmpl/number_members.php"
Change this code
Code:
<input type="text" class="input-mini validate[required,custom[number],min[1]

Step 2: in the file "administrator/components/com_eventbooking/libraries/rad/form/form.php"
Around line 235 you'll see this code
Code:
public function calculateFee()
Add these lines of code just above that function, Not In It.
Code:
// NEW FUNCTION to get # Registrants from Session public function regNumber() { $session = JFactory::getSession(); $number_registering = (int) $session->get('eb_number_registrants', ''); return $number_registering; } // END NEW FUNCTION

Step 3: in the same file "administrator/components/com_eventbooking/libraries/rad/form/form.php"
Around lines 259 and 260 you'll see this code
Code:
$formula = $field->row->fee_formula; $formula = str_replace('[FIELD_VALUE]', floatval($field->value), $formula);
Replace the code above with this code:
Code:
$formula = $field->row->fee_formula; $regNum = $this->regNumber(); // NEW CODE $formula = str_replace('[FIELD_VALUE]', floatval(($field->value) * $regNum), $formula); // NEW CODE //$formula = str_replace('[FIELD_VALUE]', floatval($field->value), $formula); // Old Code

There you have it! A way that your custom fields can multiply by the number of registrants signing up.

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
11 years 4 months ago #53033 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic $numberRegistrants * Custom Field
That's something which I will add support for in the future, but need carefully coding as this code is called on the back-end when you create new registrants as well. In backend, session->get('eb_number_registrants', ''); doesn't return number of registrants. So the fee might be wrong....

Tuan

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
11 years 4 months ago #53034 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic $numberRegistrants * Custom Field
The code above works for you. I think. But to make it available in the core, we need to code and check it carefully !

Tuan

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

More
11 years 4 months ago #53040 by mikek
Replied by mikek on topic $numberRegistrants * Custom Field
Yes it works Tuan. And I can't find any issues that it's causing. I will update if I find anything wrong.

Having this function opens up many new options. It eliminates the need for individual registration, and makes it all a full registration system. It greatly reduces the number of custom fields you would normally create for multi-option events. If you don't want the new code to multiply by registrants then just use the Fee Values box to enter the prices, and remove the [FIELD_VALUE] from the Fee Formula box.
Works like a dream!

Thanks for your help Tuan! You started me in the right direction.

Mike

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

  • Tuan Pham Ngoc
  • Away
  • Administrator
  • Administrator
More
11 years 4 months ago #53046 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic $numberRegistrants * Custom Field
OK Mike. Please keep a backup of your change for now. I will try to add support for the [NUMBER_REGISTRANTS] tag in fee formula in the future

Regards,

Tuan

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

More
9 years 3 weeks ago #95520 by Guy Bournival
Replied by Guy Bournival on topic $numberRegistrants * Custom Field
Hi Tuan,

Have you add support for NUMBER_REGISTRANTS ?
I need to multiply an fixed amount by number of registrants base on 1 field :

Individual or Group registration
Volunteering : O Yes O No
Yes : Free...
No : $200 * Number of registrants

I will like to show Volunteering field on Both individual and group registration billing form.

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

Moderators: Tuan Pham Ngoc