VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: GuidoS on August 05, 2014, 17:27:05 PM

Title: duplicate canonical url on manufacturer category page
Post by: GuidoS on August 05, 2014, 17:27:05 PM
When you open the category page of a manufacturer you will get two canonical urls. Doesn't matter if you have SEF urls on or off.

index.php?option=com_virtuemart&view=category&virtuemart_category_id=xx&virtuemart_manufacturer_id=xx

VM 2.6.6
JM 2.5.24

VM 2.9.8a
JM 3.3.3
Title: Re: duplicate canonical url on manufacturer category page
Post by: Peter Pillen on August 06, 2014, 10:24:47 AM
Some time ago the canonical url for manufacturers was added to VM as standard. It is possible that a canonical was already created by your template, creating two canonical urls in your case. Check your template override for category view if there is any line of code creating that extra canonical.
Title: Re: duplicate canonical url on manufacturer category page
Post by: GuidoS on August 06, 2014, 17:01:24 PM
I know, I asked for that functionality;) But I have tested it with a blank template and fresh installation of Joomla / virtuemart. With no other components installed.
Title: Re: duplicate canonical url on manufacturer category page
Post by: Peter Pillen on August 07, 2014, 17:06:02 PM
Quote from: GuidoS on August 06, 2014, 17:01:24 PM
I know, I asked for that functionality;)
hahaha ... And I helped out (http://forum.virtuemart.net/index.php?topic=117648.msg397663#msg397663) changing that functionality 6 months before you asked for it  ;)

VM does not make two canonicals as standard, so something is else is affecting this. Does this behaviour happen with the beez3 or beez5 standard template as well?
Title: Re: duplicate canonical url on manufacturer category page
Post by: GuidoS on August 07, 2014, 21:46:24 PM
Oh really, hahaha. Well, it's broken again:)

I have setup a new joomla 3.3.3 enviroment and installed the latest version of VM 2.9.8a. Then I created a category, manufacturer, 1 product and 2 childs. Then I selected the category and manufacturer in the parent product, not the childs. After that I created a menu item that links to the category. When I open the category with the menu item I am getting the screen on which the duplicate canonical is present. Havn't installed any other things.

[attachment cleanup by admin]
Title: Re: duplicate canonical url on manufacturer category page
Post by: Peter Pillen on August 07, 2014, 22:11:59 PM
And concerning my question about the template? Beez3 and beez5? I ask this just to exclude your template as the culprit.
Title: Re: duplicate canonical url on manufacturer category page
Post by: GuidoS on August 08, 2014, 12:12:11 PM
Can't look in to it right now but it is the standard template that is selected when you install Joomla 3.3.3
Title: Re: duplicate canonical url on manufacturer category page
Post by: Milbo on August 10, 2014, 09:34:16 AM
Hmmm, thank you both, nice conversation.

For me it seems to be a new behaviour of joomla 3.3. The first URL has all the menu item attributes, while the second one seems to be "ours". So maybe j3.3 is just adding the URL of the menuitem as canonical. So we just should not add it for j3, maybe?
Title: Re: duplicate canonical url on manufacturer category page
Post by: GuidoS on August 14, 2014, 23:30:17 PM
Yeah but the thing is that the manufacturer category view has no menu item because it's not linked. Does it take the menu item id of the last clicked menu link? It's always better to have one:)
Title: Re: duplicate canonical url on manufacturer category page
Post by: balai on August 15, 2014, 14:58:27 PM
I think it's better to replace it instead of adding it again.


         $document=JFactory::getDocument();
$canonical_url=JRoute::_('http://something.com');
$links= $document->_links;
foreach($links as $key=>$link){
if(is_array($link)){
if(array_key_exists('relation', $link) && !empty($link['relation']) && $link['relation']=='canonical'){
//found it - delete the old
unset($document->_links[$key]);
}
}
}
//add a new one
$document->_links[$canonical_url]=array('relType'=>'rel','relation'=>'canonical','attribs'=>'');

Title: Re: duplicate canonical url on manufacturer category page
Post by: GuidoS on August 18, 2014, 23:21:38 PM
I have found something else in VM2.6.8, in file com_virtuemart/views/category/view.html.php on line 88 the manufacturer_id is set as "manufacturer", $catType is set on that place but if you look at the function setCanonicalLink it expects the manufacturer_id.
Title: Re: duplicate canonical url on manufacturer category page
Post by: tophatco on September 12, 2014, 22:04:31 PM
I am having issues with this I think as well. Using Joomla 3.3.3 and VM 2.9.9b

I also have two canonical links too when you view a category or product. Examples:

For a category I get:

<link href="http://www.domain.com/storage-sheds/premium/manufacturer/?categorylayout=0&amp;showcategory=1&amp;showproducts=1&amp;productsublayout=0" rel="canonical" />
<link href="/storage-sheds/premium/manufacturer/" rel="canonical" />


The real URL is, or should be: http://www.domain.com/storage-sheds/premium

Where is this /manufacturer coming from? If I visit either http://www.domain.com/storage-sheds/premium  or http://www.domain.com/storage-sheds/premium/manufacturer I get the same page.

For a product I get:

<link href="http://www.domain.com/storage-sheds/premium/a-frames-detail?limitstart=0&amp;limit=int" rel="canonical" />
<link href="/storage-sheds/premium/a-frames-detail" rel="canonical" />


No /manufacturer in the URL at all.

---tophatco


Title: Re: duplicate canonical url on manufacturer category page
Post by: jjk on January 09, 2015, 23:12:35 PM
Joomla 3 tries to add a canonical URL using it's SEF plugin. But it does a bad job in this case. The same problem may occur on the VM product details pages.
An easy workaround is to comment out this line (approximately line 49, depending on your Joomla 3.x version) in the file
...your-root\plugins\system\sef\sef.php:

$doc->addHeadLink(htmlspecialchars($link), 'canonical');

so that it reads:

//$doc->addHeadLink(htmlspecialchars($link), 'canonical');

Preferably you should use a template override file for that.
Title: Re: duplicate canonical url on manufacturer category page
Post by: sandstorm on January 11, 2015, 20:37:21 PM
Quote from: jjk on January 09, 2015, 23:12:35 PM
An easy workaround is to comment out this line (approximately line 49, depending on your Joomla 3.x version) in the file
...your-root\plugins\system\sef\sef.php:

$doc->addHeadLink(htmlspecialchars($link), 'canonical');

so that it reads:

//$doc->addHeadLink(htmlspecialchars($link), 'canonical');

Preferably you should use a template override file for that.

I noticed this exact same problem in product pages in Joomla 3.3.6 & VM3.0.2 and was about to put a post up in the forum when I saw this one is already being discussed.
Will overriding the SEF plugin file as suggested by "JJK" stop canonicals showing for other areas of the normal Joomla site, i.e articles, etc?
Title: Re: duplicate canonical url on manufacturer category page
Post by: GJC Web Design on January 11, 2015, 21:33:46 PM
I don't know but assume it would - you need to test

Probably it would be better to make this selective .. something like

$jinput = JFactory::getApplication()->input;
$comp = $jinput->get('option');
if($comp != 'com_virtuemart') {
$doc->addHeadLink(htmlspecialchars($link), 'canonical');
}

not tested
Title: Re: duplicate canonical url on manufacturer category page
Post by: jjk on January 11, 2015, 21:50:34 PM
Quote from: sandstorm on January 11, 2015, 20:37:21 PM
Will overriding the SEF plugin file as suggested by "JJK" stop canonicals showing for other areas of the normal Joomla site, i.e articles, etc?
Yes, but when I tested the workaround with my own site, my version of Joomla (3.4dev nightly build) didn't add canonical urls into the headers of my Joomla content articles anyway. So in my case it looked like I don't have multiple urls for Joomla articles on my website. It doesn't make any sense to always add canonical urls, even if there are no multiple urls pointing to the same content. That's not what the canonical tag is designed for. Just test your website by looking at the source code of your frontpage content with/without the override in order to decide if it works for you.

I think when the Joomla developers introduced that in Joomla 3, they forgot to take into account shopping cart and forum extensions.
(A similar thing happend with the pagination. Shopping cart and forum extensions using Joomla 3.3.6 are suffering from a broken pagination)

I didn't test GJC's suggestion yet.

Title: Re: duplicate canonical url on manufacturer category page
Post by: sandstorm on January 15, 2015, 16:45:29 PM
Quote from: jjk on January 11, 2015, 21:50:34 PM
Yes, but when I tested the workaround with my own site, my version of Joomla (3.4dev nightly build) didn't add canonical urls into the headers of my Joomla content articles anyway.

Apologies confused now (It doesn't take much ;) )
Should I test with J3.4 & VM 3.0.3 first before using any workarounds?
Title: Re: duplicate canonical url on manufacturer category page
Post by: jjk on January 15, 2015, 22:57:51 PM
You may apply the suggestion from GJC Web Design either in Joomla 3.3.6 or 3.4.dev. It seems to work. However, with Joomla 3.3.6 the pagination doesn't work correctly. I've choosen the simple method to temporarily comment out the single line
$doc->addHeadLink(htmlspecialchars($link), 'canonical');
although it removes the Joomla canonical completely. (I think I don't have duplicate Joomla content anywhere, so I consider the Joomla canonical useless in my case)

I didn't test suggestion from balai yet.

You wouldn't have this problem at all if you use J2.5.28/VM3.0.3.

Title: Re: duplicate canonical url on manufacturer category page
Post by: 2cool on March 20, 2015, 12:58:00 PM
Hi There,

Just noticed my category pages show error in seo: page not indexable because this page has canonical url set to:  category/manufacturer/ ???
How can this be fixed? using lastest joomla 3.4.0 and vm 3.0.4.

Thanks,

Pas