Using com_ajax with a Hikashop group plugin

  • Posts: 195
  • Thank you received: 13
  • Hikashop Business
5 years 9 months ago #295436

-- HikaShop version -- : 3.4.1
-- Joomla version -- : 3.8.10
-- PHP version -- : 5.6.36
-- Error-message(debug-mod must be tuned on) -- : PHP Fatal error: Call to undefined function hikashop_get() in /home/threeby4/subdomains/learn/plugins/hikashop/massaction_category/massaction_category.php on line 17

I'm creating a custom plugin. Because it responds to several Hikashop events, the plugin is in the Hikashop group.

I'd like to respond to ajax requests. So I've created a function in my plugin's main class. This seemed to work at some point, but at present any time I specify group=hikashop in the URL (e.g. index.php?option=com_hikashop&plugin=myplugin&group=hikashop&format=json I get this PHP error:

PHP Fatal error: Call to undefined function hikashop_get() in /home/threeby4/subdomains/learn/plugins/hikashop/massaction_category/massaction_category.php on line 17

Probably I'm going to need to move my Ajax function to a separate custom plugin in the default ajax group. But before I take that path I thought I'm mention this issue. It doesn't seem that the massaction_category plugin should be responding by default to a com_ajax URL.

I'd appreciate any thoughts. Thanks.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

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

  • Posts: 195
  • Thank you received: 13
  • Hikashop Business
5 years 9 months ago #295472

Apologies. My URL example should have been
index.php?option=com_ajax&plugin=myplugin&group=hikashop&format=json


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

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

  • Posts: 81484
  • Thank you received: 13062
  • MODERATOR
5 years 9 months ago #295447

Hi,

This happens because com_ajax uses a normal trigger, and to use a normal trigger Joomla does this:
- First, it loads all the plugins of the target group
- Then, it calls the trigger on all the plugins of the target group which implements the trigger
The issue you have is then caused by two things:
- We assumed that plugins from the "hikashop" group would only be loaded by HikaShop (or another of our extensions), which means that we assumed that HikaShop would always be already loaded when plugins of the "hikashop" group would be loaded.
- In that mass action plugin, hikashop_get is called directly in the constructor of the class (so directly when the plugin is loaded, and not only when a trigger is called.

We'll look in adding some code on our end to avoid such issue.

Note also that HikaShop actually has it's own system to allow plugins to be called in ajax (and actually much more). Our system will allow the plugin to have its own controllers and views so you could build complete frontend and backend interfaces from only a plugin with that.
I invite you to look at the plugins/hikashop/email_history/ plugin for an example. This plugins handles the Customers>Email history menu item in the backend. The controller and the views of that area are completely in that plugin and the code is not complex so it's a good example.

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

Time to create page: 0.056 seconds
Powered by Kunena Forum