public function setCanonicalLink($tpl, $document, $categoryId)
{
$format = !empty($tpl) ? $tpl : vRequest::getCmd('format', 'html');
if ($format === 'html') {
// Remove existing canonical
foreach ($document->_links as $k => $array) {
if ($array['relation'] === 'canonical') {
unset($document->_links[$k]);
break;
}
}
// Build canonical link
$link = 'index.php?option=com_virtuemart&view=category&Itemid=' . $this->Itemid;
if ($categoryId !== -1) {
$link .= '&virtuemart_category_id=' . $categoryId;
}
// Generate final canonical URL
$canonicalUrl = JRoute::_($link, true, -1);
$uri = JUri::getInstance($canonicalUrl);
$uri->setScheme('https');
$canonicalUrl = $uri->toString(['scheme', 'host', 'port', 'path', 'query']);
$document->addHeadLink($canonicalUrl, 'canonical', 'rel');
}
}<link href="/shop/category" rel="canonical">
<link href="/shop/category/manufacturer/by-price" rel="alternate" hreflang="pl">
<link href="/en/shop/category/manufacturer/by-price" rel="alternate" hreflang="en"><link href="/shop/category" rel="canonical">
<link href="/shop/category/by-price" rel="alternate" hreflang="pl">
<link href="/en/shop/category/by-price" rel="alternate" hreflang="en">I changed the order of parameters in the router for the manufacturer — previously it was placed before the category name, which caused issues with the logical URL structure.Page created in 0.113 seconds with 13 queries.