Plugin not triggered

  • Posts: 52
  • Thank you received: 5
  • Hikaserial Standard Hikashop Essential
1 month 2 weeks ago #359740

-- 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 :

<?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 :
<?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: 1 month 2 weeks ago by marcmarc.

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
1 month 2 weeks ago #359748

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<PluginGroup><PluginName>
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.

  • Posts: 52
  • Thank you received: 5
  • Hikaserial Standard Hikashop Essential
1 month 2 weeks ago #359763

Guilty as charged, it's been a long time since I created a Joomla plugin and I forgot the name thing...
Thanks!

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

Time to create page: 0.050 seconds
Powered by Kunena Forum