Hi,
I think I know why this doesn't work for you.
You have sub menu items with the categories and in that case, the system directly use the URL of the sub menu item corresponding to the category, which skips the generation of the URL process where the canonical URL is generated if missing.
Change the code:
return JRoute::_('index.php?option=com_hikashop&Itemid='.$submenu->itemid);
to:
$url = JRoute::_('index.php?option=com_hikashop&Itemid='.$submenu->itemid);
// save the URL as canonical URL if the "force canonical URLs on listings" setting is activated and the canonical URL is not filled in
$config = hikashop_config();
$force_canonical = $config->get('force_canonical_urls',1);
if(isset($cid->category_canonical) && empty($cid->category_canonical) && $force_canonical == 2) {
$newObj = new stdClass();
$newObj->category_id = $cid->category_id;
$newObj->category_canonical = $url;
$categoryClass = hikashop_get('class.category');
$categoryClass->save($newObj);
}
return $url;
in the file components/com_hikashop/views/category/view.html.php and that should help.
Let us know how it goes so that we can add that patch on our end too.