Supported versions and Router

  • Posts: 30
  • Thank you received: 1
  • Hikashop Business
1 year 2 months ago #349026

-- HikaShop version -- : 4.7.1
-- Joomla version -- : 4.2.7
-- PHP version -- : 7.4

Hello,
I'm currently creating a better finder plugin for hikashop and I'm running into serious issues with the router. The URLs are simply completely wrong, which is mainly due to the Itemid being hardcoded to the URL. When I look at the router, I also see issues there and it would start with unnecessarily complex code there. The question would be, which Joomla versions you are supporting, because unless you are support Joomla from before 3.6, you could drop half the code in your router.

To be specific:

<?php
$jversion = preg_replace('#[^0-9\.]#i','',JVERSION);
if(version_compare($jversion,'4.0.0','>=')) {
	class hikashopRouter extends Joomla\CMS\Component\Router\RouterBase {

		public function build(&$query) {
			return _HikashopBuildRoute($query);
		}

		public function parse(&$segments) {
			return _HikashopParseRoute($segments);
		}
	}
}

function HikashopBuildRoute( &$query ) { return _HikashopBuildRoute($query, ':'); }

function _HikashopBuildRoute( &$query, $separator = '-' )
{
...
}

function HikashopParseRoute( $segments ) { return _HikashopParseRoute($segments, ':'); }

function _HikashopParseRoute( &$segments, $separator = '-' )
{
....
}

function hikashop_retrieve_url_id(&$vars,$name){
...
}

could be replaced with
<?php
class hikashopRouter extends JComponentRouterBase {
	public function build(&$query) {
		...
	}

	public function parse(&$segments) {
		...
	}
	protected function hikashop_retrieve_url_id(&$vars,$name){
	...
	}
}
Where ... is the actual program code. That code would be working from Joomla 3.6 onwards.

Besides that, it would be nice if the router would discover the Itemid dynamically similar to how the core does it. That means that you don't have to store the Itemid in the finder and if you change your sites structure, move a category to a different place or something similar, your URLs would still be correct.

If you are interested in a rewrite of either the router or the finder plugin, feel free to contact me.

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
1 year 2 months ago #349028

Hi,

We still want to support all the versions of Joomla 3 for the time being.

When we developed first HikaShop, we were just providing the current itemid in the URL. When no itemid was provided, that was fine too as Joomla's routing would just let it go. I think it's started with Joomla 3, where Joomla's routing would generate an error when no menu item was provided for a URL request. And thus, we modified the code here and there to provide a menu item id in the URLs being generated before sending them to the Joomla router for SEFing.

It could indeed be a nice improvment to discover the itemid dynamically in the router when it is missing in the URL to be SEFed.
We do have some code in administrator/components/com_hikashop/classes/menus.php like getCheckoutMenuIdForURL (to get the itemid for the checkout) or getItemidFromCategory (to try to get the itemid from a category_id) or loadAMenuItemId ( to try to load a menu item based on the view/layout pair being provided ).
So using a combinason of these might be a good idea, as it will probably speed up the coding.

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

  • Posts: 30
  • Thank you received: 1
  • Hikashop Business
1 year 2 months ago #349037

The goal is, that the router itself can dig up the right data it needs. In worst case, you could find out everything just by having the product ID. Joomla hands in everything else just to improve performance. Generally on the projects I've been working on, the URLs have been quite an issue with Hikashop and improving this area would really be good.

Do you have any information in regards to which versions of Hikashop are used on which Joomla version? Ideally I would advise you to stop support for Joomla 3 with the EOL of Joomla 3, but if you want to provide longer support, at least limit it to Joomla 3.10. Considering that Joomla 3.0 has been released over 10 years ago and Joomla 3.6 is also over 6 years old, I would reduce support there now.

Regarding my above code: You can still improve that by simply calling the new router class inside the old functions, similar to how Joomla does it.

function contentBuildRoute(&$query)
{
	$app = JFactory::getApplication();
	$router = new ContentRouter($app, $app->getMenu());

	return $router->build($query);
}

If you need support in regards to the router or the finder plugin, please contact me.

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

Time to create page: 0.058 seconds
Powered by Kunena Forum