0

I was trying to add the facebook like button to my product pages but then I noticed that the like counter has different numbers depending on where the page was accessed from and the URL it has.

Magento by default creates 3 URL rewrites for each new product automatically.

  • If I access a product from my home page it has the URL mysite/product-name.html.
  • If I access a product from a base category it has the URL mysite/base-category/product-name.html
  • If I access a product from a sub-category it has the URL mysite/base-category/sub-category/product-name.html

all of the above have different like counts and are treated as different pages. is there a way to merge the like counts while still keeping the SEO friendly URLs? what are the best practices in this regard?

Thank you.

3 Answers 3

2

I guess using canonical meta tags to link the pages with each other will solve the issue. To enable them, Login to admin, go to System > Configuration > Catalog and then click on the option labelled "Search Engine Optimizations". Enable for products or categories accordingly.

5
  • hi thank you for the answer. sorry I didn't get back to you sooner. I am still testing it out to see if it actually fixed the issue. I won't forget to accept this answer if it works. :)
    – Jake
    Aug 25, 2014 at 14:03
  • Ok I finished testing it and it seems to work but I noticed something strange about it's behavior and I was hoping you could explain it. when I access some links through my homepage the breadcrumbs at the top display this path: home>product-name but after entering the product page from it's sub-category the breadcrumbs display home>base-category>sub-category>product-name throughout the site and no matter where I access the page from. is it due to caching?
    – Jake
    Aug 25, 2014 at 14:10
  • this is a default behavior, direct accessing of product will only show home > product while accessing the product through categories will include them in breadcrumb as well.
    – MTM
    Aug 25, 2014 at 14:16
  • that's true but at the moment after activating the canonical meta tags, when I access the products from my home page the breadcrumbs show home > base-category > sub-category > product
    – Jake
    Aug 25, 2014 at 14:18
  • probably due to cache
    – MTM
    Aug 25, 2014 at 14:21
1

You can also set product url to NOT include category path in admin > system > configuration > catalog > seo area.

1
  • The problem is that I wanted to preserve the categories in the path.
    – Jake
    Aug 27, 2014 at 17:16
0

In the end the canonical meta tags did not solve the issue like I initially thought they did.

I ended up solving this issue by creating a helper function that query the url rewrite collection for a product id and then retrieves the product url with the deepest category levels (the url with the most '/'). and then I used this helper to get the product url for the social buttons, and I used it for the item link in list.phtml and new.phtml.

so now all my links refer to a single rewrite.

I don't know if this is the best solution but it does the job for me at least for now.

Helper code:

public static function getFullProductUrl(
Mage_Catalog_Model_Product $product
) {
$url = Mage::getModel('core/url_rewrite')->getCollection()
->addFilter('is_system', '1')
->addFilter('product_id', $product->getId())
->addFilter('store_id', Mage::app()->getStore()->getId())
->addFieldToFilter('category_id', array('gt' => '0'));
$items = $url->getItems();
$count = 0;
foreach ($items as $item) {
    $sc = substr_count($item->getRequestPath(),'/');
    if ($sc > $count){
        $count = $sc;
        $which = $item;
    }
}
if (!$which->getRequestPath()) {
return $product->getUrlPath();
}
return Mage::getBaseUrl() . $which->getRequestPath();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.