Skip to main content

Title: 500 error "A key is required" when opening checkout without Itemid (Jooml

More
4 hours 33 minutes ago - 4 hours 31 minutes ago #100000242 by Sinus
-- url of the page with the problem -- : www.greenfirezuidlaren.nl/
-- HikaShop version -- : 6.6.0 (Business)
-- Joomla version -- : 6.1.3
-- PHP version -- : 8.4.25
-- Browser(s) name and version -- :  Chrome 155.0
-- Error-message(debug-mod must be tuned on) -- : : 0 - A key is required

Hi,

I ran into a 500 error on our shop ( www.greenfirezuidlaren.nl ) and tracked it down to the checkout controller. It looks like a Joomla 6 compatibility issue, so I thought I'd share what I found.

Our setup: Joomla 6.1.3, PHP 8.4.25, HikaShop Business 6.6.0 and YOOtheme Pro 5. The checkout menu item is set in the HikaShop configuration (checkout_itemid 434, SEF name "afrekenen").

What happens: when a visitor has something in their cart and opens the checkout without an Itemid in the URL, they get a 500 page saying "0 - A key is required". For example:

www.greenfirezuidlaren.nl/component/hikashop/checkout

We mostly saw this through old add-to-cart links like /component/hikashop/product/updatecart/add-1/cid-66, which redirect to that URL.

A few things I noticed while testing:
- With an empty cart (or no session at all) there's no error, you just get redirected to the product listing.
- As soon as there's any Itemid in the URL, even one that doesn't exist, HikaShop redirects nicely to the checkout menu item.
- It also happens with tmpl=component and format=raw, so it's not the template.

I briefly turned on Joomla debug to get the stack trace:

1  JROOT/libraries/vendor/joomla/database/src/DatabaseQuery.php:1890
2  Joomla\Database\DatabaseQuery->bind()
  JROOT/libraries/vendor/joomla/database/src/DatabaseQuery.php:1988
3  Joomla\Database\DatabaseQuery->bindArray()
  JROOT/libraries/src/Language/Associations.php:126
4  Joomla\CMS\Language\Associations::getAssociations()
  JROOT/administrator/components/com_menus/src/Helper/MenusHelper.php:281
5  Joomla\Component\Menus\Administrator\Helper\MenusHelper::getAssociations()
  JROOT/components/com_hikashop/controllers/checkout.php:159
6  checkoutController->show()
  JROOT/libraries/src/MVC/Controller/BaseController.php:738
7  hikashopController->execute()
  JROOT/administrator/components/com_hikashop/helpers/helper.php:3167
8  require_once()
  JROOT/components/com_hikashop/hikashop.php:85

So as far as I can tell, line 159 of checkout.php calls MenusHelper::getAssociations() with an empty menu item id when there's no Itemid. Joomla 6 then hands an empty array to bindArray(), which throws the exception. Joomla 5 didn't complain about this, which is probably why it hasn't come up before.

I noticed the changelog for 6.5.1 mentions a change to this same block (the multilingual menu associations in the checkout, which now only runs when the Joomla classes exist). Maybe a check on the menu item id could be added there as well. We're on 6.6.0, which is the latest version available to us.

A simple guard would probably fix it: only call getAssociations() when the menu item id is above 0, or fall back to the configured checkout_itemid first.

For now I've added this to our .htaccess as a workaround, and that works fine:
Code:
RewriteCond %{QUERY_STRING} !(^|&)Itemid=[0-9] RewriteRule ^component/hikashop/checkout(/show)?/?$ /kachelbrandstoffen/afrekenen [R=301,L,QSA]
Because of that workaround, the link above now redirects instead of showing the error. 


Best regards,
Sinus
Last edit: 4 hours 31 minutes ago by Sinus.

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

More
2 hours 15 minutes ago #100000245 by nicolas
Hi,

Thank you for the detailed analysis, you are right. The cause is a change in Joomla 6.2: Joomla's association lookup now accepts several ids and fails with "A key is required" when it receives no id, which is what the checkout passes when the URL has no Itemid. Note that this code only exists from Joomla 6.2.0 on (the Associations.php line in your stack trace), so your site is most likely running a 6.2.x version rather than 6.1.3.

We have fixed it: HikaShop now only looks up the menu associations when there is a menu item id, so /component/hikashop/checkout redirects again to the checkout menu item set in the configuration.

Download the install package of HikaShop on our website and install it on yours in order to get the patch and it should then work fine.

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

Time to create page: 0.128 seconds
Powered by Kunena Forum