0

I am trying to show a layered navigation on homepage. I m using magento 1.9.0. and inserted following xml in Layout Update XML

<reference name="left">
    <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>

Then in app\code\core\Mage\Catalog\Model\layer.php modified function getCurrentCategory() as follows to get root category on home-page:

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 = false;
            $this->setData(’current_category’, $category);
        }
    }

    // added to make this work for front page:
    if(is_null($category) || $category == false) {
        $home_category = Mage::getModel(’catalog/category’)->load(4); //number must correspond to ‘all products page’ category
        $this->setData(’current_category’, $home_category);
        $category = $this->getData(’current_category’);

        return $category;

    }

    //end addition

    return $category; 
}

But Following error has occurred:

Fatal error: Call to a member function load() on a non-object in app\code\core\Mage\Catalog\Model\Layer.php on line 174

Please help.

2

Try check you single quote You should use ' instead ’

1

I don't know this related to your or not,I understood this way that's why i am posting

$cat = Mage::getModel('catalog/category')->load(enter you category id);

like

$cat = Mage::getModel('catalog/category')->load(43);

I think this is help full for you

1

You need to set category id to layer for getting layer navigation

<action method="setCategoryId"><category_id>yourcatId</category_id></action>

Code should like this:

 <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml">
 <action method="setCategoryId"><category_id>yourcatId</category_id></action>
 </block>
0

I found an answer to my question and it works it like a charm.

just edit in app\code\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 = false;
        $this->setData('current_category', $category);
    }
}

// added to make this work for front page:
if(is_null($category) || $category == false) {
    $home_category = Mage::getModel('catalog/category')->load(4); //number must correspond to 'all products page' category
    $this->setData('current_category', $home_category);
    $category = $this->getData('current_category');

    return $category;

}

//end addition

return $category; 
}

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.