Canonical links in Manufacturer products pages

Started by sandstorm, June 20, 2013, 15:55:29 PM

Previous topic - Next topic

sandstorm

I use SH404SEF and in the main all works well with Virtuemart 2. 
But I only just noticed recently (after lots of digging around) that canonical linking doesnt work when you are view manufacturer product details pages.
I use these pages a lot and have menu links set up directly to list the product by manufacturer.

The canonical link tag just points back to the home page when view manufacturer product pages or pagination variations of the same page.

I asked for help on SH404 forum, but they just said I suspect this may be because virtuemart ( as always, seams they dont like doing things on right way, is not inserting the right ItemID value in the canonical tags ) .

So i was just wanting to know where to look to find what i need to fix this for manufacturers product pages.
Is it in components/com_virtuemart or administrator/com_virtuemart ?



I found this below in administrator/com_virtuemart/models/product.php at line 689-692

I see products and categories mentioned but not manufacturer? do you think this is where the problem will be?

Do I just need to find out the code for manufacturer and add that?


// Add the product link  for canonical

            $child->canonical = 'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $virtuemart_product_id . '&virtuemart_category_id=' . $child->virtuemart_category_id;

            $child->link = JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $virtuemart_product_id . '&virtuemart_category_id=' . $child->virtuemart_category_id);



J3.6.4 / PHP7.0.12
VM3.0.16

jjk

If I remember correctly, sh404sef achieves VM2 compatibility by disabling itself on VM2 pages (correct me if I'm wrong). Joomla/VM2's own SEF features are working very well. However, it's true that in VM2's manufacturer views, the canonical points to the homepage, but I wonder if rel="next" and rel="prev" would be better for the manufacturers product pages than the 'canonical'. Basically a 'canonical' is telling Google that there is duplicate content (different urls, same product) and the canonical points to the prefered url.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Peter Pillen

I would like to find the code that makes the canonical appear in the manufacturer and category view. Can someone point me in the right direction?

Reason ... I would like to avoid a canonical tag being created in the manufacturer view that links to the main page. I can understand that for example a photocamera can be placed in the category "reflexcamera" and "professional camera" at the same time... creating duplicate content that must be solved with canonicals. But... a Nikon camera will never be found in the Canon category. In theory every manufacturer page should be unique. So the canonical in the manufacturer category view should only point to the first page of that manufacturer (limitstart=0)

The problem in search engines is this below

option=com_virtuemart&view=category&virtuemart_category_id=&virtuemart_manufacturer_id=2&lang=nl
--> this view with images does not get indexed by Google because a canonical points to the virtuemart main page

option=com_virtuemart&view=manufacturer&virtuemart_category_id=&virtuemart_manufacturer_id=2&lang=nl
--> this view without productimages gets indexed by google

the first page is visually more attractive and should be indexed instead of the manufacturer info

Maxim Pishnyak

com_virtuemart.2.0.22\administrator\components\com_virtuemart\models\product.php
com_virtuemart.2.0.22\components\com_virtuemart\views\category\view.html.php
You can support Community by voting for Project on the JED
https://extensions.joomla.org/extension/virtuemart/#reviews
Join us at
https://twitter.com/virtuemart

Peter Pillen


Peter Pillen

This seems to work for me (I also started a topic in VM coding central for this)

purpose of this code change
1. Creates a canonical for the manufacturer page that points to the first page with products of that manufacturer INSTEAD of pointing to the virtuemart main page
2. In categories where a manufacturer filter is applied, the canonical will still point to the category canonical (same as before)
3. On the manufacturer info page without the products, the canonical points to the manufacturer page where the products are visible (canonical points to view=category INSTEAD of view=manufacturers)

In short ... every category has one canonical to the first page, every manufacturer has one canonical to its own page with view= category so that products are visible. And when applying a manufacturer filter in a category, the canonical remains the same.

file: components\com_virtuemart\views\category\view.html.php
search for function setCanonicalLink

<?php
public function 
setCanonicalLink($tpl,$document,$categoryId){
// Set Canonic link
if (!empty($tpl)) {
$format $tpl;
} else {
$format JRequest::getWord('format''html');
}
if ($format == 'html') {
// Adapt canonical to manufacturer or category
$vm_canon_cat_id JRequest::getVar('virtuemart_category_id');
$vm_canon_mf_id =  JRequest::getVar('virtuemart_manufacturer_id');
if ($vm_canon_cat_id==and $vm_canon_mf_id>0){
$canonType='manufacturer';
$canonId=$vm_canon_mf_id;
}else{
$canonType='category';
$canonId=$categoryId;
}
$document->addHeadLinkJRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_'.$canonType.'_id='.$canonIdFALSE) , 'canonical''rel''' );
}
}
?>


file: components\com_virtuemart\views\manufacturer\view.html.php


line added under the $document->setTitle
<?php
                        $document
->setTitle(JText::_('COM_VIRTUEMART_MANUFACTURER_DETAILS').' '.strip_tags($manufacturer->mf_name));

//added so that the canonical points to page with visible products
$document->addHeadLinkJRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_manufacturer_id='.$virtuemart_manufacturer_idFALSE) , 'canonical''rel''' );
?>

sandstorm

I had a developer have a look at this a while ago and this is what he came up with, which works for me.

In the file /components/com_virtuemart/views/category/view.html.php
from Line 245 with the note //Set Canonical link  We modified the code to look like this;

// Set Canonic link

if (!empty($tpl)) {

$format = $tpl;

} else {

$format = JRequest::getWord('format', 'html');

}

if ($format == 'html') {
// mod for manufacturer canonic link

if ($virtuemart_manufacturer_id = JRequest::getInt('virtuemart_manufacturer_id',0 ))

$document->addHeadLink( 'index.php?option=com_virtuemart&view=category&virtuemart_manufacturer_id='.$virtuemart_manufacturer_id , 'canonical', 'rel', '' );

else

$document->addHeadLink( JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$categoryId) , 'canonical', 'rel', '' );

//end of mod

}


I don't know which way is best for the cleanest type of code? But I know my way works great for me and we started seeing difference within 2-3 days in Google
J3.6.4 / PHP7.0.12
VM3.0.16

Peter Pillen

#7
It's almost the same, from one thing...

For example:

let's say we have an online car catalogue and a visitor is browsing through the sportscar section ...
--> canonical will be set to "sportscar"

the visitor then applies a filter in the sportscar section for the brand "mercedes"
--> canonical in sandstorm code will change to "mercedes"
--> canonical in P2 code will remain "sportscar"

In my code the canonical is only set to the manufacturer through the manufacturer module link or when applying a brand filter in the toplevel category of your VM page. The canonicals are only used by searchbots and I can't say for sure if they use/browse the filters.

@sandstorm ... change the code in components\com_virtuemart\views\manufacturer\view.html.php as I described. Because normally you will be indexing two versions of manufacturer pages in your case. A page with products and a page without products.


sandstorm

Thanks Peter, I'll give yours a try and see what happens.

On another Note I though that this was fixed in VM2.0.22b, but after I just tested.
The manufacturer product pages still show a canonical of "/" , this is the page that you get once you look at the manufactruer page & click the "View Manufacturer products" button/link
J3.6.4 / PHP7.0.12
VM3.0.16

Peter Pillen

@sandstorm ... mine is working completely correct

Please note that I have changed two files in my case

sandstorm

The upgrade overwrote my changes in my single file, so I will give your code a try. Thanks

But my point was, I though that this code modification may not actually be needed now, as I thought i was added to the core already?
J3.6.4 / PHP7.0.12
VM3.0.16

sandstorm

Using 2.0.22c, do these changes still need to be added to get canonical working correctly?
I read your thread in VM coding central and thought it had now been implemented?
Or has it just been implemented in the SVN?

Also the VM coding central thread mentions that some code is not working properly?
Is there an updated version of codes to change or is the code in post#5 in this thread correct to use?

Thanks
Andy
J3.6.4 / PHP7.0.12
VM3.0.16