#JUGL meetings are held on the 3rd Tuesday of each month

NEXT MEETING:

News 

Find Joomla! and Joomla! London related news here.  We show the latest security updates, Joomla! announcements, information about past and upcoming meetings, and anything else we think might be relevant.

rseventspro.jpgI implemented the popular RSEvents component for a client. Everything went well including setting up the individual paypal payments option which was a specific requirement for my client. This was to be used by franchisees to collect their own payments.

We were 1 hour before go-live(literally) when my client asked "how do we turn off VAT for some owners and not others?"...

...good question I thought...after looking into it, my response was "you don't!".

Cut a long story short, this is not possible on out of the bag RSEvents (upto Rev4).

Nevertheless it was an absolute requirement for my client, and what they want they get...

What follows is one way to accomplish this but please be warned, you do have to modify core RSEvents files, not something most people want to do. The usual disclaimer of responsibility applies...

Before you do anything else BACKUP and then test your backup file!

Wherever you modify files, always leave a comment to remind you what you did. Use a moniker that is unique and easy to search for. Don't worry about long comments, the more info you leave a future you, the better.

**Update

I have now implemented this for v4 too.  I have modded the walk through to show v3 line numbers (**) & v4 line numbers [**].

Now you're prepared, we're ready, the following files will need to be changed:

  • /component/com_rseventspro/models/rs_eventspro.php
  • /component/com_rseventspro/helpers/rs_eventspro.php
  • /component/com_rseventspro/helpers/events.php
  • /component/rs_events/views/rseventspro/tmpl/edit.php
  • /plugins/system/rsepropaypal/rsepropaypal.php

Essentially what we're going to do is add an extra option into each event called "me_vat", this allows owners to select for themselves whether they want VAT to charged or not. Then later on, at the purchase stage, we're going to check for this option to decide on the price to be charged and then we're going to verify that the right amount was taken by paypal before confirming the payment and updating the subscriptions...simple!

 

Step 1 - Adding the 'me_vat' Option

This can be done through an HTML override:

 

View of file structureCopy the contents of the folder:

/components/com_rsevents/views/rseventspro/tmpl

in to:

/templates/yourtemplatename/html/com_rseventspro/

Now, copy:

edit.php & edit.xml

into a new subfolder called /rseventspro.

Once that is done, we are ready to edit the override file; this is a much better option than editing component files directly.  These changes won't be affected by any upgrades but you will need to check and possibly re-apply the following changes to an updated tmpl/edit.php file if you do upgrade.

What to change:

In /templates/youtemplate/html/com_rseventspro/rseventspro/edit.php

For v3, around line (861), in between the paypal_email entry and the notify_me entry, add the following code:

< p>

< input id="me_vat" name="options[me_vat]" type="checkbox" value="1" class="rs_check" options['me_vat']) && $this->options['me_vat'] == 1) ? 'checked="checked"' : ''; ?> />
< label for="me_vat" class="rs_inline">

(Take out the spaces in the opening tags)

For v4, at [876], in between the paypal_email entry and the notify_me entry, add the following code:

< p>

< input id="me_vat" name="jform[options][me_vat]" type="checkbox" value="1" class="rs_check" options['me_vat']) && $this->options['me_vat'] == 1) ? 'checked="checked"' : ''; ?> /> 
< label for="me_vat" class="rs_inline">

(Take out the spaces in the opening tags)

Step 2 - Modify the core RSEvents Pro files

We need to update the helper files and model files to acknowledge our new 'me_vat' option, when the component is setting its defaults.  These are core files so create a copy of the existing file first, rename the copy to filename.bak before editing the original file.

In /components/rseventspro/helpers/events.php

At around line (189)[221], you should find the "function getDefaultOptions()"

Add an option at the end for 'me_vat' like this:

function getDefaultOptions() { 

	return array(
'enable_rating' => null,
'enable_fb_like' => 1,
'enable_twitter' => 1,
'enable_gplus' => 1,
'start_date' => 1,
'end_date' => 1,
'show_description' =>1,
'show_location' => 1,
'show_categories' => 1,
'show_tags' => null,
'show_files' => 1,
'show_contact' => 1,
'show_map' => 1,
'show_export' => 1,
'show_invite' => 1,
'show_postedby' => 1,
'show_repeats' => 1,
'me_vat' => null
);
}

 

This edit is for v3 only:

    1. /component/com_rseventspro/helpers/rs_eventspro.php


At around line (1862) in the "function options($options)"

Add an option for 'me_vat' like this:

$defaults = array('enable_rating' => 1, 'enable_fb_like' => 1, 'enable_twitter' => 1, 'enable_gplus' => 1, 'start_date' => 1, 'end_date' => 1, 'show_description' => 1, 'show_location' => 1, 'show_categories' => 1, 'show_tags' => 1, 'show_files' => 1, 'show_contact' => 1, 'show_map' => 1, 'show_export' => 1, 'show_invite' => 1, 'show_postedby' => 1, 'show_repeats' => 1, 'me_vat' => 1);

 

That's the helpers taken care of, now the model:

In /components/com_rseventspro/models/rs_eventspro.php

 

At around line (1696)[2390], change:

$plugintaxes = $this->_app->triggerEvent('rsepro_tax',array(array('method'=>&$payment, 'total'=>$total)));

 

(v3) to :

$plugintaxes = $this->_app->triggerEvent('rsepro_tax',array(array('method'=>&$payment, 'total'=>$total, 'eid'=>$cid)));

[v4] to:

 

$plugintaxes = $this->_app->triggerEvent('rsepro_tax',array(array('method'=>&$payment, 'total'=>$total, 'eid'=>$id)));

This basically adds an extra piece of info that is sent to the rsepro_tax function in the RSEvents paypal plugin. We'll need this later.

Step 3 - PayPal Plugin for RSEvents Pro

That is basically all the areas I found that need changing in the RSEvents Pro core system. The last piece of the puzzle is how the purchase process is handled by the optional PayPal plugin for RSEvents. We will need to manipulate that slightly to do what we want.

This is not the RSForm PayPal plugin, This is specifically for RSEvents and is an optional purchase.

In /plugins/system/rsepropaypal/rsepropaypal.php

At around line (63)[63] I added:

For v3:

function getOptions($id) {

	$db =& JFactory::getDBO();
$db->setQuery("SELECT options FROM #__rseventspro_events WHERE id = " . $id . " ");
$options = $db->loadResult();
$options = trim($options);
if (!empty($options)) {
$options = unserialize($options);
if ($options !== false)
$vat = $options['me_vat'];
return $vat;
}
return null;
}

For v4, it's a little more complicated:

public function getOptions($id) {

	$db = JFactory::getDbo();
        $query = $db->getQuery(true);
$query->clear()
    ->select($db->qn('options'))
            ->from($db->qn('#__rseventspro_events'))
            ->where($db->qn('id').' = ' . $id);
        $db->setQuery($query);
        $options = $db->loadResult();
        if (!empty($options)) {
            $registry = new JRegistry;
            $registry->loadString($options);
            $options = $registry->toArray();
            if ($options !== false) {
                $vat = $options['me_vat'];
                return $vat;
            }
        }
        return null;
}

Then, around line (212)[230], after the last "}" of the "if ($details->late_fee)" and before the line "if (!empty($details->tax)) {", I added:

 

For v3 & v4:

$id = $details->ide;

$vat = $this->getOptions($id);
if ($vat == 1) {

 

The closing "}" needs to be added after the closing "}" of "if (!empty($details->tax)) {"

We're basically wrapping one "if" statement in another, which checks if our 'me_vat' option is set.

The code should look like:

$id = $details->ide;

$vat = $this->getOptions($id);
if ($vat == 1) {
if (!empty($details->tax))
{
$total = $total + $details->tax;
$html .= '' ."\n";
$html .= ''.JText::_('RSEPRO_PLG_PLUGIN_PAYPAL_TICKETS_TAX').''."\n";
$html .= ''.rseventsproHelper::currency($details->tax).''."\n";
$html .= ''."\n";
}
}

 

Then at around(265)[267], change:

if (!empty($details->tax)) {

	$thetax += $details->tax;
}

To:

if ($vat == 1) { // Also modded for VAT mod above

	if (!empty($details->tax)) {
$thetax += $details->tax;
}
}

At around line (520)[467], in the rsepro_tax funtion, for both v3 & v4, change it from:

function rsepro_tax($vars) {

  if (isset($vars['method']) && $vars['method'] == $this->rsprooption)
{
require_once(JPATH_SITE.DS.'components'.DS.'com_rseventspro'.DS.'helpers'.DS.'rseventspro.php');
$total = isset($vars['total']) ? $vars['total'] : 0;
$tax_value = $this -> _params -> get('tax_value', 0);
$tax_type = $this -> _params -> get('tax_type', 0);
return rseventsproHelper::setTax($total, $tax_type, $tax_value);
}
}

To:

function rsepro_tax($vars) {

  $id = $vars['eid'];
$vat = $this->getOptions($id);
if ($vat == 1) { // Also modded for VAT mod above
if (isset($vars['method']) && $vars['method'] == $this->rsprooption)
{
require_once(JPATH_SITE.DS.'components'.DS.'com_rseventspro'.DS.'helpers'.DS.'rseventspro.php');
$total = isset($vars['total']) ? $vars['total'] : 0;
$tax_value = $this -> _params -> get('tax_value', 0);
$tax_type = $this -> _params -> get('tax_type', 0);
return rseventsproHelper::setTax($total, $tax_type, $tax_value);
}
}
}

 

For v4, place your additions after:

        if (!$this->canRun())

            return;

Which was added to the function in this version.

You'll be happy to hear that is the last of the coding changes. If you've followed me this far, the last few changes won't be a challenge.

 

Step 4 - Tidy Ups

We'll need to add a language override for our setting in the Edit page. You'll need to do this for frontend and backend, there is an option for this when creating the override.

In Extensions/Language Manager/Overrides, add an override for "RSEPRO_EVENT_OWNER_VAT". I made mine "VAT to be charged?"

All going well, that should be that. Make sure you test all varieties of purchase, with VAT and without before you rollout to a production installation. I've done my best to be as accurate as possible but the line numbers have not been referenced against the blank file, so they could be out a little. I will update this with accurate line numbers.

One other thing, I have not checked this against rev4 other than having a quick look over the files modified to see if there was much in the way of changes. I couldn't see any, so my theory is that will work for rev4. I fully expect this to be added to RSEventsPro at a future date, so hopefully they will make a better job than I have.

Good Luck!