- Posts: 74
- Thank you received: 7
Plugin not triggered
2 years 6 months ago - 2 years 6 months ago #359740
by marcmarc
Plugin not triggered was created by marcmarc
-- HikaShop version -- : 5.0.3
-- Joomla version -- : 4.4.3
-- PHP version -- : 8.1.27
Hi,
I'm writing a plugin and I'm stuck at a very basic step : the plugin is not triggered.
My plugin is "discovered" installed and enabled.
It's inside the directory /plugins/hikashop/plgHikashopTest/
I've stripped the php file "plgHikashopTest.php" at the bare minimum as is :
the xml "plgHikashopTest.xml" is :
So if triggered when a product is created or updated it should, well… die.
Nothing is triggered! Nothing die.
Any idea?
Thanks
-- Joomla version -- : 4.4.3
-- PHP version -- : 8.1.27
Hi,
I'm writing a plugin and I'm stuck at a very basic step : the plugin is not triggered.
My plugin is "discovered" installed and enabled.
It's inside the directory /plugins/hikashop/plgHikashopTest/
I've stripped the php file "plgHikashopTest.php" at the bare minimum as is :
Code:
<?php defined('_JEXEC') or die('Restricted access');
class plgHikashopTest extends JPlugin
{
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
}
public function onAfterProductCreate(&$element, &$status)
{
die();
}
public function onAfterProductUpdate(&$element, &$status)
{
die();
}
}
?>
the xml "plgHikashopTest.xml" is :
Code:
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="1.0.0" method="upgrade" group="hikashop">
<name>plgHikashopTest</name>
<creationDate>mars 2024</creationDate>
<version>1.0.0</version>
<author></author>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<copyright></copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<description>plgHikashopTest</description>
<files>
<filename plugin="plgHikashopTest">plgHikashopTest.php</filename>
</files>
<params addpath="/components/com_hikaserial/params">
</params>
<config>
<fields name="params" addfieldpath="/components/com_hikaserial/fields">
</fields>
</config>
</extension>
So if triggered when a product is created or updated it should, well… die.
Nothing is triggered! Nothing die.
Any idea?
Thanks
Last edit: 2 years 6 months ago by marcmarc.
Please Log in or Create an account to join the conversation.
2 years 6 months ago #359748
by nicolas
Replied by nicolas on topic Plugin not triggered
Hi,
The class of the plugin is not correct.
As per docs.joomla.org/Special:MyLanguage/J3.x:..._a_Plugin_for_Joomla the class of the plugin needs to be plg
The <PluginGroup> in your case is "hikashop", and the <PluginName> in your case is plgHikashopTest so the class name should be:
plugHikashopPlgHikashopTest
I suppose you wanted the name of your plugin to be "test" so that the class name would be plgHikashopTest, but in that case, you need to rename your plugin files to test.php and test.xml and change the plugin name to "test" in your XML.
An easy way to find this is to move the die outside the class of the PHP file.
If the die is not called, then it means that the plugin PHP file is not called at all by PHP. So either the plugin is not enabled in the plugins manager or the file has a wrong filename.
If the die is called, then move the die in the __construct function which is called when the class is initialized. If the die is not called in the constructor function, then it can only be the class name which is wrong. If the die is called, then it means that the function name is wrong or the extension is not triggering the event for some reason.
That's basically what I do when I create a plugin and my event function is not being called
The class of the plugin is not correct.
As per docs.joomla.org/Special:MyLanguage/J3.x:..._a_Plugin_for_Joomla the class of the plugin needs to be plg
The <PluginGroup> in your case is "hikashop", and the <PluginName> in your case is plgHikashopTest so the class name should be:
plugHikashopPlgHikashopTest
I suppose you wanted the name of your plugin to be "test" so that the class name would be plgHikashopTest, but in that case, you need to rename your plugin files to test.php and test.xml and change the plugin name to "test" in your XML.
An easy way to find this is to move the die outside the class of the PHP file.
If the die is not called, then it means that the plugin PHP file is not called at all by PHP. So either the plugin is not enabled in the plugins manager or the file has a wrong filename.
If the die is called, then move the die in the __construct function which is called when the class is initialized. If the die is not called in the constructor function, then it can only be the class name which is wrong. If the die is called, then it means that the function name is wrong or the extension is not triggering the event for some reason.
That's basically what I do when I create a plugin and my event function is not being called
The following user(s) said Thank You: marcmarc
Please Log in or Create an account to join the conversation.
2 years 6 months ago #359763
by marcmarc
Replied by marcmarc on topic Plugin not triggered
Guilty as charged, it's been a long time since I created a Joomla plugin and I forgot the name thing...
Thanks!
Thanks!
Please Log in or Create an account to join the conversation.
Time to create page: 0.250 seconds