Layered navigation on homepage in magento 1.9 Call to a member function load() on a non-object in Error Occured

magento.stackexchange https://magento.stackexchange.com//questions/30388

  •  11-12-2019
  •  | 
  •  

Question

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.

Était-ce utile?

La solution 4

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; 
}

Autres conseils

Try check you single quote You should use ' instead ’

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

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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top