How to fix layered navigation filer URL in Magento?

How to fix layered navigation filer URL in Magento?

April 2, 2015 Magento is really good eCommerce CMS in terms of functionality. Layered Navigation is really good feature of Magento to filter the product in frontend side. Only problem with the layered navigation filter is that it work with query string. for Example www.yourwebsitesite.com/category.html?color=120. Another problem is with category filter. For example we have main category "Cat1" and a sub category "sub1", we will have this url: www.yourwebsitesite.com/cat1/sub1.html With filter: www.yourwebsitesite.com/cat1.html?cat=5 Obviously is an issue for SEO with duplicated content. We can fix the layered navigation filter thing by overriding the getUrl() method in the at:/app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php Of Course, from a developer point of view, you can make local version of it and modify the code as explained below: Locate the function at line 57, it should look like this:
public function getUrl()
{
    $query = array(
        $this->getFilter()->getRequestVar()=>$this->getValue(),
        Mage::getBlockSingleton('page/html_pager')->getPageVarName() => null // exclude current page from urls
    );
    return Mage::getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true, '_query'=>$query));
}
Now you need to edit this code and replace with:
public function getUrl()
{
    if($this->getFilter()->getRequestVar() == "cat"){
        $category_url = Mage::getModel('catalog/category')->load($this->getValue())->getUrl();
        $return = $category_url;
        $request = Mage::getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true));
        if(strpos($request,'?') !== false ){
            $query_string = substr($request,strpos($request,'?'));
        }
        else{
            $query_string = '';
        }
        if(!empty($query_string)){
            $return .= $query_string;
        }
        return $return;
    }
    else{
        $query = array(
            $this->getFilter()->getRequestVar()=>$this->getValue(),
            Mage::getBlockSingleton('page/html_pager')->getPageVarName() => null // exclude current page from urls
        );

        return Mage::getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true, '_query'=>$query));
    }
}
Its really quick way to fix it and checked with Magento version 1.9 Feel Free to contact me any time.

Related Posts

from my blog


How To Reset Admin Password in Magento

January 20, 2017

As an ecommerce website developer or magento website developer, sometime we  get the a situation when we forget the magento website admin access detail. To reset the password of any...

How to show all attribute after layered navigation filter in Magento

April 10, 2015

Magento Layered Navigation is really good for filter the product but problem is that, if we select any attribute like color or price all other attribute hide which are not...

How to add new language in Magento store

October 3, 2012

Are you looking for adding new language in your Magento store. Follow these easy steps and enjoy your multilingual site : Go here: http://www.magentocommerce.com/translations Select the language which you want to...