Monday, June 18, 2012

Magento Layered navigation at home page


Follow as
1.Update XML layout via CMS > Manage Pages > Homepage > Layout Update XML box:
<reference name="left">
    <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>

2.Modify a core method getCurrentCategory() in core/Mage/Catalog/Model/Layer.php
public function getCurrentCategory()
    {
        $category = $this->getData('current_category');

        if (is_null($category)) {
            if ($category = Mage::registry('current_category')) {
                $this->setData('current_category', $category);
            }
            else {
                $category = Mage::getModel('catalog/category')->load($this->getCurrentStore()->getRootCategoryId());
                $this->setData('current_category', $category);
            }
        }

        if($category != Mage::registry('current_category')) {          
            $home_category = Mage::getModel('catalog/category')->load(3);
            $this->setData('current_category', $home_category);
            $category = $this->getData('current_category');
            //return $category;
        }
     
        return $category;
    }

9 comments:

  1. there is an error in your code in this line
    public function getCurrentCategory()

    ReplyDelete
  2. Greate!

    Thnks, It works, after trying a couple of code o other sites

    ReplyDelete
  3. Is not filtering when I apply above code. I have the newest magento 1.7.0.2

    ReplyDelete
    Replies
    1. try to set as a current category from any category for home page.

      Delete
  4. hello, can you help me. How to show a filter for a specific category. as here rezina.cc

    ReplyDelete
  5. nothing happen on my home page..please can you help me?

    ReplyDelete