[Skip to main content](#vessel-content)

#   Useless database query in hikashopPluginsClass::getByName()

##

- **[Denitz](/forum/user/42054-denitz "View Denitz's Profile")**
- [![Denitz's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/42054-denitz "View Denitz's Profile") Topic Author
- [ Offline](/forum/user/42054-denitz)

Less More

- Posts: 31
- Thank you received: 2
-
-

10 months 1 week ago -  10 months 1 week ago [\#369858](#369858) by [Denitz](/forum/user/42054-denitz "View Denitz's Profile")  *[Useless database query in hikashopPluginsClass::getByName()](/forum/25-install-update/909999-useless-database-query-in-hikashoppluginsclass-getbyname#369858 "-- HikaShop version -- : 6.1.1 -- Joomla version -- : 5.4.1 -- PHP version -- : 8.3.0  It's better to use native Joomla plugin helper to get plugin params, it utilizes native Joomla caching of plugins.")* was created by *[Denitz](/forum/user/42054-denitz "View Denitz's Profile")*

-- HikaShop version -- : 6.1.1
-- Joomla version -- : 5.4.1
-- PHP version -- : 8.3.0

It's better to use native Joomla plugin helper to get plugin params, it utilizes native Joomla caching of plugins.
Code:

public function getByName(string $type, string $name): ?\stdClass { $plugin = \Joomla\CMS\Plugin\PluginHelper::getPlugin($type, $name); if ($plugin) { $this-&gt;loadParams($plugin); } return $plugin; }

Last edit: 10 months 1 week ago by [Denitz](/forum/user/42054-denitz "View Denitz's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwOTk5OS11c2VsZXNzLWRhdGFiYXNlLXF1ZXJ5LWluLWhpa2FzaG9wcGx1Z2luc2NsYXNzLWdldGJ5bmFtZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86326
- Thank you received: 14288
-
-

10 months 1 week ago [\#369863](#369863) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Useless database query in hikashopPluginsClass::getByName()](/forum/25-install-update/909999-useless-database-query-in-hikashoppluginsclass-getbyname#369863 "-- HikaShop version -- : 6.1.1 -- Joomla version -- : 5.4.1 -- PHP version -- : 8.3.0  It's better to use native Joomla plugin helper to get plugin params, it utilizes native Joomla caching of plugins.")*

Hi,

Thanks again for your feedback.

While you're correct, this is sometimes not possible as we need to be able to load plugins which PluginHelper::getPlugin won't find.
JPluginHelper::getPlugin won't return anything if the plugin is disabled in the Joomla plugins manager. But the $pluginClass-&gt;getByName function will be able to provide the data of the plugin in that case.
Making the change you suggest would prevent the code there to work properly.

However, I can see that over the years, we've used getByName more and more all over the place and not having a cache mechanism can lead to a lot of unnecessary MySQL queries while the cases were we specifically need to load an unpublished plugin are quite rare in the code base of HikaShop.

After some deliberation, we decided to do it like this: Code:

function getByName($type, $name, $fromCache = true){ if($fromCache){ $result = JPluginHelper::getPlugin($type, $name); } else { $query = 'SELECT * FROM '.hikashop_table('extensions',false).' WHERE folder='.$this-&gt;database-&gt;Quote($type).' AND element='.$this-&gt;database-&gt;Quote($name).' AND type=\'plugin\''; $this-&gt;database-&gt;setQuery($query); $result = $this-&gt;database-&gt;loadObject(); } if(!empty($result)) $this-&gt;loadParams($result); return $result; }

This way, the PluginHelper::getPlugin function will be used almost everywhere, and where we specifically want to be able to get the plugin data regardless of the enabled state and we do not need cache, we can set the extra parameter to false to get the previous behavior.

Note that HikaShop will still be compatible with Joomla 3 in the foreseeable future so we still want to use JPluginHelper with a class alias for the \Joomla\CMS\Plugin\PluginHelper class when necessary.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwOTk5OS11c2VsZXNzLWRhdGFiYXNlLXF1ZXJ5LWluLWhpa2FzaG9wcGx1Z2luc2NsYXNzLWdldGJ5bmFtZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[Denitz](/forum/user/42054-denitz "View Denitz's Profile")**
- [![Denitz's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/42054-denitz "View Denitz's Profile") Topic Author
- [ Offline](/forum/user/42054-denitz)

Less More

- Posts: 31
- Thank you received: 2
-
-

10 months 6 days ago [\#369868](#369868) by [Denitz](/forum/user/42054-denitz "View Denitz's Profile")  Replied by *[Denitz](/forum/user/42054-denitz "View Denitz's Profile")* on topic *[Useless database query in hikashopPluginsClass::getByName()](/forum/25-install-update/909999-useless-database-query-in-hikashoppluginsclass-getbyname#369868 "-- HikaShop version -- : 6.1.1 -- Joomla version -- : 5.4.1 -- PHP version -- : 8.3.0  It's better to use native Joomla plugin helper to get plugin params, it utilizes native Joomla caching of plugins.")*

OK, thanks for feedback!
To be honest, I don't see the cases when disabled plugin should be loaded, disabled state means that it should not be used.
And Joomla3 compatibility looks a bit strange at the end of 2025, keeping compatibility with Joomla3 and Joomla4 freezes the development process. Hope you will abandon Joomla3 and Joomla4 as soon as possible to get the benefits of new Joomla6.

Small remark: if(!empty($result)) is useless here, it's enough to have if(!$result) and omit useless function call.
And $database has quote() method but not Quote()

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwOTk5OS11c2VsZXNzLWRhdGFiYXNlLXF1ZXJ5LWluLWhpa2FzaG9wcGx1Z2luc2NsYXNzLWdldGJ5bmFtZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86326
- Thank you received: 14288
-
-

10 months 6 days ago [\#369872](#369872) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Useless database query in hikashopPluginsClass::getByName()](/forum/25-install-update/909999-useless-database-query-in-hikashoppluginsclass-getbyname#369872 "-- HikaShop version -- : 6.1.1 -- Joomla version -- : 5.4.1 -- PHP version -- : 8.3.0  It's better to use native Joomla plugin helper to get plugin params, it utilizes native Joomla caching of plugins.")*

Hi,

Thanks again for your feedback.

> To be honest, I don't see the cases when disabled plugin should be loaded, disabled state means that it should not be used.

For example, at the end of the data import from another ecommerce extension, if there is a compatible URL fallback plugin (which can redirect the URLs of the products of that other ecommerce solution to the products in HikaShop), the system will display a specific message about this plugin so that the user can enable it via the Joomla plugins manager.
To decide whether to display or not the message, the system looks for the presence of the corresponding plugin being installed. And obviously, you don't want to enable these plugins by default.

> And Joomla3 compatibility looks a bit strange at the end of 2025, keeping compatibility with Joomla3 and Joomla4 freezes the development process.

Joomla version usage statistics still points at Joomla 3 being the majority:
[ w3techs.com/technologies/details/cm-joomla](https://w3techs.com/technologies/details/cm-joomla)
While new websites are not made with Joomla 3 anymore, I don't see a reason to not support users stuck with Joomla 3. This allows us the possibility to easily push security updates to them if necessary in the future. Supporting it also makes for an easier migration process for users that want to migrate their HikaShop to the latest version of Joomla.

> Hope you will abandon Joomla3 and Joomla4 as soon as possible to get the benefits of new Joomla6.

Supporting Joomla 3 doesn't stop us from implementing improvements made by more recent versions of Joomla.
For example, in 2025, we've added support for email templates which were added in Joomla 5.2, and we have an integration with the Smart Search component which isn't available on Joomla 3, or with the black mode of Joomla 5 and 6.

> if(!empty($result)) is useless here, it's enough to have if(!$result) and omit useless function call.

That's indeed correct. Note however that it should be if($result) to keep the same code logic.

> And $database has quote() method but not Quote()

Yes. I think that in the past the function was advertised with a capital letter and since the case doesn't matter in function names unless you have two functions with the same letters but different casing, we didn't bother changing it.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwOTk5OS11c2VsZXNzLWRhdGFiYXNlLXF1ZXJ5LWluLWhpa2FzaG9wcGx1Z2luc2NsYXNzLWdldGJ5bmFtZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[Denitz](/forum/user/42054-denitz "View Denitz's Profile")**
- [![Denitz's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/42054-denitz "View Denitz's Profile") Topic Author
- [ Offline](/forum/user/42054-denitz)

Less More

- Posts: 31
- Thank you received: 2
-
-

10 months 6 days ago [\#369874](#369874) by [Denitz](/forum/user/42054-denitz "View Denitz's Profile")  Replied by *[Denitz](/forum/user/42054-denitz "View Denitz's Profile")* on topic *[Useless database query in hikashopPluginsClass::getByName()](/forum/25-install-update/909999-useless-database-query-in-hikashoppluginsclass-getbyname#369874 "-- HikaShop version -- : 6.1.1 -- Joomla version -- : 5.4.1 -- PHP version -- : 8.3.0  It's better to use native Joomla plugin helper to get plugin params, it utilizes native Joomla caching of plugins.")*

OK, many thanks for explanation, Happy Holidays!

The following user(s) said Thank You: [nicolas](/forum/user/63-nicolas "View nicolas's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwOTk5OS11c2VsZXNzLWRhdGFiYXNlLXF1ZXJ5LWluLWhpa2FzaG9wcGx1Z2luc2NsYXNzLWdldGJ5bmFtZT90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.102 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
