in Joomla, Tips and Tricks

Virtuemart2.0 content plugin support/fix for joomla1.6+

I see virtuemart2 is compatible with joomla 1.6 , hope for 1.7 too. I see there is a issue for content plugin compatibility for vm2 in joomla1.6. Then checked the vm2 code where the plugin event if fired. I see the plugin trigger method is not compatible with 1.6 content plugin structure, the hook name is for old joomla 1.5 series

note: paths are windows style
folder components\com_virtuemart\views\productdetails open file view.html.php line 97

[code language=”php”]
if ( VmConfig::get(‘enable_content_plugin’,0)) {
// add content plugin //
$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin(‘content’);
$product->text = $product->product_desc;
$params = "";
//var_dump($product);
$results = $dispatcher->trigger(‘onPrepareContent’,array (& $product, & $params, 0));
$product->product_desc = $product->text;
}
[/code]

Here the content plugin trigger event is for 1.5 series. from joomla 1.6 the “onContentPrepare” and also takes one more input.

So for line 104 there should be a check for joomla version and add conditional event hook.

It’s not hard to check the joomla version. sample code used in k2 component

[code language=”php”]
// Determine Joomla! version
if(version_compare( JVERSION, ‘1.6.0’, ‘ge’ )) {
define(‘K2_JVERSION’,’16’);
}
else {
define(‘K2_JVERSION’,’15’);
}
[/code]

here is how the code can be for both 1.5 and 1.6+ content plugins support

[code language=”php”]
if ( VmConfig::get(‘enable_content_plugin’,0)) {
// add content plugin //
// Determine Joomla! version
if(version_compare( JVERSION, ‘1.6.0’, ‘ge’ )) {
define(‘VMJ2_JVERSION’,’16’);
}
else {
define(‘VMJ2_JVERSION’,’15’);
}

$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin(‘content’);
$product->text = $product->product_desc;
$params = "";
//var_dump($product);
if(VMJ2_JVERSION==’16’){
$results = $dispatcher->trigger(‘onContentPrepare’,array (‘com_virtuemart.productdetails’,& $product, & $params, 0));
}
else{
$results = $dispatcher->trigger(‘onPrepareContent’,array (& $product, & $params, 0));
}

$product->product_desc = $product->text;
}
[/code]

Note2: I have opened a thread on virtuemart forum here.

Leave a Reply