Calling Joomla! Plugins
July 8, 2007 – 10:22 amJoomla mambots are great and wonderful but they seem not to work with other components. For example how do u call a joomla plugin into your Virtue Mart Component? In order for the Joomla mambots to work with other components you will have to take three main steps :
-
Get access to the global $_MAMBOTS object.
-
Load a plugin group (in our case, content plugins).
-
Trigger an event.
Thus, the code for running some text, say $text_to_process, through the Joomla! content plugins would look like this:
global $_MAMBOTS;
$_MAMBOTS->loadBotGroup( ‘content’ );
$tmp_row = new stdClass();
$tmp_params = new mosParameters(”);
$tmp_row->text = $text_to_process;
$_MAMBOTS->trigger( ‘onPrepareContent’, array( &$tmp_row, &$tmp_params ), true );
$text_to_process = $tmp_row->text;
For my example i am gonna stop on presenting how you could use “tabs and slides” plugin with VirtueMart component. Normally it should work but with few modification all is possible. Calling the “tabs and slides” plugin in the Product page on VirtueMart is done like this :
You’ll need to edit shop.product_details.php :
Find :
$template = preg_replace(”/{vm_lang:([^}]*)}/ie”, “\$VM_LANG->\\1″, $template);
Insert after it :
global $_MAMBOTS;
$_MAMBOTS->loadBotGroup( ‘content’ );
$tmp_row = new stdClass();
$tmp_params = new mosParameters(”);
$tmp_row->text = $template;
$_MAMBOTS->trigger( ‘onPrepareContent’, array( &$tmp_row, &$tmp_params ), true );
$template = $tmp_row->text;
Notice that the text we are running the plugins on is contained in the $template variable.
Now just call the plugin from your product description (the long description) in VirtueMart.
You may need to call a the “tabs and slides” mambot to the shop browse page aswell, for that you need another modification.
To do this, you’ll need to modify shop.browse.php.
Near the top of the file, look for this line (19):
mm_showMyFileName( __FILE__ );
Right after this add just the code that loads the plugins:
global $_MAMBOTS;
$_MAMBOTS->loadBotGroup( ‘content’ );
$plug_row = new stdClass();
$plug_params = new mosParameters(”);
Notice that we’re loading the plugin group at the beginning of the file, but not actually triggering the plugins yet. We’ll trigger the plugins later on the category descriptions and short product descriptions separately.
Now, to run plugins on category descriptions, look for these two lines (83-84):
echo '<div style="width:100%;float:left;">';echo $desc;
Right between those two lines, add this code to trigger the plugins:
$plug_row->text = $desc;
$_MAMBOTS->trigger( 'onPrepareContent', array( &$plug_row, &$plug_params ), true );
$desc = $plug_row->text;
The variable $desc contains the category description.
Let’s also make plugins work for the short product descriptions that appear on the shop browse pages. In the same file, shop.browse.php, look for this line (476):
echo $product_cell;
Right before it, add the following plugin code:
$plug_row->text = $product_cell;
$_MAMBOTS->trigger( ‘onPrepareContent’, array( &$plug_row, &$plug_params ), true );
$product_cell = $plug_row->text;
The variable $product_cell contains the short product description.
Now just add the appropriate plugin call to a category description or short product description in VirtueMart, and you’ll have Joomla! plugins displayed in VirtueMart’s shop browse pages.