Jump to content

How to manage duplicate products with a href="canonical"


mozofi

Recommended Posts

Hello,

 

I am looking for a solution (module) that will help me do this:

 

We have one main product which comes in different size and we created different versions of products for each. So, obviously, the products are the same but only with their size different. We want to add the canonical tag for each variation that will point to the main product. Is there any way to specify the canonical URL manually for each product in the header? I've searched over the modules over the internet and there are a few ones that seem to integrate the canonical tag but I think they do this automatically only for the paginations and products which have dynamic URL's (different size, color, etc. )

 

Please let me know how we can integrate this feature in our store.

 

Have a great day,

-Viku

Link to comment
Share on other sites

  • 2 weeks later...

First guys thank you for the answers. I was rather looking for some configuration in the back-office(or even additional module) that should do it. However I didn't find such and went on adding it to the source code, which is not very elegant, but did the job.

Link to comment
Share on other sites

  • 2 weeks later...

For God's sake I must be really dumb but I still can not figure this out. What field should I use to enter the tag? Is that in the product setting page in Prestashop? Short description or Detailed one? I tried to use the html tag in the detailed description on a product but it does not display in the source code, it automatically strips off in the editor while I press Save. Also, I use the Canonical URL PRO module to assist me with managing duplicate content on paginations, sortings, search results, etc. By using it, I get a canonical URL on each product page which contains the tag like <link rel="canonical" href="product URL" /> but I want to set it to <link rel="canonical" href="original product URL" />

 

Thanks.

Link to comment
Share on other sites

Hi mozofi,

<link rel="canonical" href="targetProductUrl">

should be added to <head> element of the product page. I added it to header.tpl of the main theme. Here is the code:

{if isset($cannonical_url) AND !empty($cannonical_url)}
        <link rel="canonical" href="{$cannonical_url}"/>
{/if}

This $cannonical_url variable should be initialized first. Here's the code in ProductController.php

    public function initContent()
    {
//.....
            $cannonical_url = '';
            if(key_exists((int)$this->product->id, Product::$cannonical_redirects))
            {
                 $ref_id = Product::$cannonical_redirects[(int)$this->product->id];
                 $cannonical_url = $this->context->link->getProductLink($ref_id);
            }

And this code in Product.php

    public static $cannonical_redirects = array(100 => 99, 101 => 99, 98 => 94, 97 => 94, 96 => 94, 95 => 94);

The last array is a list of all canonical redirects. For example product with id 100 will be redirected to product with id 99 and so on.

 

 

p.s. As i said this is probably far from the best solution, just the quickest option at this time.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...