Notice: ABPro's Stripe payment processor uses the Legacy Checkout and is not SCA compatible. read more..

How-To

Have a UDF selection adjust cost

This How-to will show a way to have a UDF dropdown selection modify the booking costs.

First I want to point out that UDFs are not designed to effect booking cost. Extras and Servcies do that.

An example where this technique might be handy is where you have UDFs for address and you want to have the 'County' drop down add costs to booking because it costs you more to go there. 

 

There are three challenges here:

  1. UDFs are generic and placed on the screen as simple udf1, udf2, udf3, etc, so you will need to determine what udf you are wanting to trigger the cost change with.
  2. The calcTotal() javascript function will need to be modified to adjust the costs
  3. The changing of a UDF does not trigger re-calculation of costs so you will need to make it call calTotal().

 

The procedure here only works for non-resource specific UDFs. 

 

Step 1.

Determine UDF to trigger cost changes on.

Open your booking screen, then use your browser's 'View Source' feature to look at the page source. Search the source for a known UDF value. In the case of the dropdown list of counties, look for a county name. 

In this example I have a UDF called 'Event Type' and I want to charge more for a 'Birthday Party' event. I search for 'Birthday'

<td colspan="2" valign="top">
  <selectname="user_field2_value" id="user_field2_value" class="sv_apptpro_request_dropdown"
  title="">
     <optionvalue="Birthday Party" selected=true >Birthday Party</option>
     <optionvalue="Team Party" >Team Party</option>
     <optionvalue="Other" >Other</option>
   </select>
   <inputtype="hidden" name="user_field2_udf_id" id="user_field2_udf_id" value="8" />

</td>

Now that I have the code for the 'Event Type' UDF I can get the HTML element name, in this case it is "user_field2_value".

Note, as the booking screen is built the UDFs are just placed on screen in order and given incrementing names. If you change the order of your UDFs the name for the one you want will change.

 

Step 2.

Modify the calcTotal() function.

Edit file script.js, around line 1399 look for:

calcSeatsTotal(); // also sets res_rate

// -------------------------------------------------------------------
// start date/time = end date/time -> do nothing
// -------------------------------------------------------------------

This is deep in the calcTotal() function.

 

Change to:

calcSeatsTotal(); // also sets res_rate

my_udf_dropdown_value = document.getElementById("user_field2_value").options[document.getElementById("user_field2_value").selectedIndex].value;
// for testing you can uncomment the line below to check you have the correct user_field selected
//alert(my_udf_dropdown_value);
switch(my_udf_dropdown_value){
  case "Birthday Party":
    res_rate = res_rate + .01;
    break;
  case "Team Party":
    res_rate = res_rate + .07;
    break;
}
rate = parseFloat(res_rate);


// -------------------------------------------------------------------
// start date/time = end date/time -> do nothing
// -------------------------------------------------------------------

 

In my example here I do a switch on the HTML element name 'user_field2_value' that I got from step 1 above.

For 'Birthday Party' I will add $0.01 to the booking rate, for 'Team Party' I will add $0.07.

This is client side code so you will need to refresh your browser to reload scritp.js.

 

Step 3

Make changing the UDF drop down trigger a re-calculation of costs on the booking screen.

Edit the booking screen \components\com_rsappt_pro2\views\booking_screen_gad\tmpl\default.php

(this is booking screen specific, the above view file is for the GAD Booking screen)

### EDIT ###
The code to change is now located in files:
\components\com_rsappt_pro3\sv_codeblocks\sv_codeblock_udfs.php
\components\com_rsappt_pro3\sv_codeblocks\sv_codeblock_udfs_mobile.php
### END EDIT ###

 

Around line 679 97 look for:

<?php } else if($udf_row->udf_type == 'List'){
    $aryOptions = explode(",", JText::_(stripslashes($udf_row->udf_radio_options))); ?>
    <select name="user_field<?php echo $i?>_value" id="user_field<?php echo $i?>_value" class="sv_apptpro_request_dropdown"
    title="<?php echo JText::_(stripslashes($udf_row->udf_tooltip)) ?>">
    <?php
    foreach ($aryOptions as $listitem){ ?>

 

Add an onchange..

<?php } else if($udf_row->udf_type == 'List'){ 
    $aryOptions = explode(",", JText::_(stripslashes($udf_row->udf_radio_options))); ?>
    <select name="user_field<?php echo $i?>_value" id="user_field<?php echo $i?>_value" class="sv_apptpro_request_dropdown"
    title="<?php echo JText::_(stripslashes($udf_row->udf_tooltip)) ?>" onchange="calcTotal();"
    <?php 
    foreach ($aryOptions as $listitem){ ?>

 

### EDIT ####

The onchange above is for general UDFs, for resource specific UDFs the UDF code is built by a server AJAX call when the user selects a resource...

The resource specific UDFs html code is built by php in file: getSlots.php
The section starts around line 389 with..
// ************************************
// get udfs for the resource
// ************************************

The code to add a list type is added around line 504 staring with..
} else if($udf_row->udf_type == "List"){

Around line 506 look for and add red code:
$out .= " <select name=\"user_field".$udf_number."_value\" id=\"user_field".$udf_number."_value\" class=\"sv_apptpro_request_dropdown\" ".
" onchange="calcTotal(); ".
"title=\"".(blockIETooltips($apptpro_config->use_jquery_tooltips)?"":JText::_(stripslashes($udf_row->udf_tooltip)))."\"> ";


 

 

That's it.

Now when the customer selects 'Birthday Party' the booking cost will go up by $0.01.