0

I use these lines to get the data of a product in the catalog,

// Get product data.
$_helper = $this->helper('catalog/output');
$_product_id = Mage::registry('product')->getId();
$_product = Mage::getModel('catalog/product')->load($_product_id);

What about if I want to get the data of a category in the catalog?

$_helper    = $this->helper('catalog/output');
$_category  = $this->getCurrentCategory();
echo Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail();

I get this error,

Fatal error: Call to a member function getId() on a non-object in ...\default\template\page\html\banner-category.phtml on line 4

I tried with these as well but the same error,

$_helper = $this->helper('catalog/output');
$_category_id = Mage::registry('category')->getId();
echo Mage::getModel('catalog/category')->load($_category_id)->getThumbnail();

Any ideas?

1 Answer 1

0

Try with this:

$_category = Mage::registry('current_category');
if ($_category) { //you are on the category page
    echo $_category->getThumbnail();
}
else {
    //you are not in a category page
}
2
  • In my case: Fatal error: Call to a member function getThumbnail() on null in...
    – TonkBerlin
    Jul 27, 2018 at 21:50
  • Are you using the same code as above? If $_category is null then how did it get passed the 'if' condition?
    – Marius
    Jul 28, 2018 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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