Page 1 of 1

[vQmod] Product Canonical Link Category or Brand Path 1.5.x

Posted: Tue Nov 15, 2011 7:33 pm
by uksitebuilder
These vQmods will change the default product canonical link:

There is a choice of 2, so pick which one you want to use

Category Path for Canonical Link in Product Page

NOTE - This will only work if you have linked your products to 'one' category or subcategory (not both or multiple)

If your products are linked to multiple categories then it will revert back to default OC canonical ink

change canonical link from

Code: Select all

yourstore.com/product-name
to

Code: Select all

yourstore.com/category/subcategory/product-name
OR

Brand Path for Canonical Link in Product Page

NOTE - This will only work if you have linked your product to a brand/manufacturer.

If you haven't, then it will revert back to default OC canonical ink

change canonical link from

Code: Select all

yourstore.com/product-name
to

Code: Select all

yourstore.com/brand/product-name
Don't have vQmod installed or can't install it, here are the manual edit instructions

Category Path for Canonical Link in Product Page

Edit: catalog/controller/product/product.php

Find

Code: Select all

$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
change to

Code: Select all

if($this->model_catalog_product->getCategoryPath($this->request->get['product_id'])!='0'){
    $this->document->addLink($this->url->link('product/product', 'path=' . $this->model_catalog_product->getCategoryPath($this->request->get['product_id']) . '&product_id=' . $this->request->get['product_id']), 'canonical');
}else{
    $this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
}
edit: catalog/model/catalog/product.php

find

Code: Select all

}
?>
add before

Code: Select all

	public function getCategoryPath($product_id) {
		$query = $this->db->query("SELECT COUNT(product_id) AS total, category_id as catid FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
		
		if($query->row['total']==1){
			$path = array();
			$path[0] = $query->row['catid'];
			
			$query = $this->db->query("SELECT parent_id AS pid FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$path[0] . "'");

			$parent = $query->row['pid'];
			
			$p = 1;
			while($parent>0){
				$path[$p] = $parent;
				
				$query = $this->db->query("SELECT parent_id AS pid FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$parent . "'");
				$parent = $query->row['pid'];
				$p++;
			}
		
			$path = array_reverse($path);
			
			$fullpath = '';
			
			foreach($path as $val){
				$fullpath .= '_'.$val;
			}
		
			return ltrim($fullpath, '_');
		}else{
			return '0';
		}
	}			
OR

Brand Path for Canonical Link in Product Page

Edit: catalog/controller/product/product.php

Find

Code: Select all

$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
change to

Code: Select all

if($product_info['manufacturer_id']!='0'){
    $this->document->addLink($this->url->link('product/product', 'manufacturer_id=' . $product_info['manufacturer_id'] . '&product_id=' . $this->request->get['product_id']), 'canonical');
}else{
    $this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
}

Re: [vQmod] Product Canonical Links inc Category Path 1.5.x

Posted: Tue Nov 15, 2011 10:48 pm
by Maansy
Nice work mate :)

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Tue Nov 15, 2011 11:46 pm
by uksitebuilder
updated and added an alternative method for brand/manufacturer path as canonical product link

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Fri Jan 06, 2012 4:21 pm
by strtfr
Thank you very much.

Unfortunately I cannot seem to get 2 to work.

My product has 1 category and one brand.

it still is http://example.com/product instead of http://example.com/brand/product

1.5.3 vqmod 2.1.5


EDIT: This mod only sets the can. url in source? Not address bar?

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Wed Jan 11, 2012 6:57 pm
by uksitebuilder
correct - it is a canonical link in the <head> section of the page, not the address bar.

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Sun Jan 15, 2012 12:00 am
by tobul
just for knowledge- you think that link with category is better than how it today?
from SEO view..?

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Mon Jan 16, 2012 7:24 pm
by uksitebuilder
Certainly - Only problem with that and the default OpenCart setup is that you can put products in multiple categories. In that instance it is not easy to know which category or category branch to use

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Tue Jan 17, 2012 12:08 am
by tobul
I will try it many thanks :joker:

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Tue Mar 27, 2012 2:04 pm
by visnetmedia
Hi I am wanting to recognise the actual brands for products for SEO so before the manufacturer id can I put
http://www.mystore.com/brands/manufacturerid/product
using the actual text like this:

Code: Select all


$this->document->addLink($this->url->link('product/product', 'manufacturer_id=' . brands/$product_info['manufacturer_id'] . '&product_id=' . $this->request->get['product_id']), 'canonical');


Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Sat Mar 31, 2012 5:21 am
by snappyfish
So if you have a single product linked to one category only, What is regarded as the best canonical structure to use for the best SEO?

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Tue Apr 03, 2012 3:44 pm
by dunks
how to get this work with feature module??

feature module on homepage link to www.example.com/canon-camera

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Tue Apr 03, 2012 8:20 pm
by uksitebuilder
It does not change the links themselves, just the canonical URL in the header of the product page

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Wed Apr 04, 2012 1:10 am
by dunks
hi uksitebuilder :)

if i click from homepage feature module product
and the link product page is http://www.example.com/canon-camera

status in seo tool is :

-page not indexable , the canonical url set to http://www.example.com/cat1/cat2/cat3/canon-camera

can u help me?? ;D

this is inside <head>

Code: Select all

<link rel="canonical" href="http://www.example.com/cat1/cat2/cat3/canon-camera">
* i think the problem will same for latest module , special module and bestseller module

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Wed Apr 04, 2012 6:03 pm
by uksitebuilder
There's nothing to help with. You wither want the page to have the category paths as it's canonical link or you dont.

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Mon Apr 16, 2012 7:37 pm
by msmith
Nice vQmod, but it's not working for me in 1.5.2.1, have you tested it in this version?

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Tue Apr 17, 2012 6:19 am
by Klimskady
I am using this on 1.5.2.2, so if it works for me it should work with your version, if you go on to one of your products and check your page source are you sure it doesn't have canonical in the head section?

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Mon Feb 18, 2013 10:32 pm
by reticlesystems
Hello there,

i put the category, so my product links shows path_id aswell for categories.

But it doesnt seem to work! :( Can u please have a look?

http://www.techtronicsdubai.com

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Thu Jan 23, 2014 11:28 am
by DragonJ
uksitebuilder:

Would you be able to update these to work with 1.5.5.1 ?

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Thu Feb 27, 2014 3:51 pm
by ThuNderGr
it doesnt work in 1.5.6

UPDATE: It works fine... but have in mind that you product has to be in ONLY ONE category in order to work.

Re: [vQmod] Product Canonical Link Category or Brand Path 1.

Posted: Fri May 09, 2014 3:33 am
by sander23
Hi, this vqmod seems like it could be my saviour, but I need help please. I have products in multiple categories. That means that I have to use the second option (brand), as I understand. I copied the second vqmod "manufacturer" in the vqmod directory, but what do I do now? I don't understand the instructions:

change canonical link from
CODE: SELECT ALL
yourstore.com/product-name

to
CODE: SELECT ALL
yourstore.com/brand/product-name

What do I do, where do I change this...How to make this thing work.. I'm using OC 1.5.5.1

Please help me out with this

Thanks so much for your time,