onBeforeCategoryListing

  • Posts: 42
  • Thank you received: 3
1 year 6 months ago #345115

-- url of the page with the problem -- : eduquay.satumalaysiahosting.com/vendor-category

Hi there,

I'm facing a problem regarding Category API, I have gone through the documentation, but it does not work.
www.hikashop.com/support/documentation/6...eCategoryListingLoad

My intention is to display specific categories by some conditions.

Code to trigger the plugin


JPluginHelper::importPlugin('onbeforecategorylistingload');
$dispatcher=JDispatcher::getInstance();
$dispatcher->trigger( 'onBeforeCategoryListingLoad', array(&$filters,&$order,&$this->rows[0],$id));



Plugin function
class plgsystemonBeforeCategoryListingLoad extends JPlugin {

	/**
	 * Constructor.
	 *
	 * @param 	$subject
	 * @param	array $config
	 */
	function __construct(&$subject, $config = array()) {
		// call parent constructor
		parent::__construct($subject, $config);
	}

	function onBeforeCategoryListingLoad(&$filters,&$a,&$b,$c){

               // Testing purpose
		$fp = fopen('file2.txt', 'w');
		$write["a"]="ab";
		fwrite($fp, print_r($write, TRUE));
		fclose($fp);

	}
}

Last edit: 1 year 6 months ago by nicolas.

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

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
1 year 6 months ago #345117

Hi,

There are three things you seem to be confused about:
- The folder of the plugin (or its type)
- The name of the plugin
- The event implemented by the plugin

With the call to JPluginHelper::importPlugin(); you need to provide the folder of the plugin. Usually, for a HikaShop plugin the folder is "hikashop". However, looking at the class name, it seems that you've chosen to use the "system" folder. In that case, you need to write "system" as parameter of that function call.

The code

$dispatcher=JDispatcher::getInstance();
$dispatcher->trigger();
is for Joomla 1.5, 2.5 and 3. It won't work on Joomla 4. Instead, you now need to use:
$app = JFactory::getApplication();
$app->triggerEvent();
This new code works on both J3 and J4 (and maybe even in J2.5).

The class name of a Joomla plugin should be:
plg + folder + name
So if your plugin's folder is "system", and its name is "custom", the class name should be:
plgSystemCustom
You need to use to camel case ( en.wikipedia.org/wiki/Camel_case#Current_usage_in_computing ) syntax (upper case for the first letter of the folder and of the name) or Joomla won't find the class of your plugin.

Now, a plugin normally has a XML file. And it's important the information in the XML correspond to the class name of the PHP file or it won't find the PHP file. As you didn't provide the XML file, I can't say if there is a problem in it.
Finally, the name of the files is also important (it should be the name of the plugin) and the plugin needs to be enabled in the joomla plugins manager.

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

Time to create page: 0.056 seconds
Powered by Kunena Forum