0
votes

i am getting an error during search ,i want to load the details from the products but i am getting an error with an certain category and i am getting back this error:

Fatal error: Call to a member function getName() on a non-object in /home/xxxxxx/home/xxxxxxx/www/test/app/design/frontend/default/blank/template/catalog/product/view.phtml on line 130

the code i am using is:

 $_helper = $this->helper('catalog/output');
 $_product = $this->getProduct();
 $cat=$_product->getCategory()->getName();

the same code work fine when approaching the products without the search option.(directly)

Could someone tell me why i get this error?

By the way this error only occur for the category name not the rest

Or could someone tell me how to get the category by product id in magento.

Txs in advance...

1

1 Answers

1
votes

Try inserting the following before your final line:

$product = Mage::getModel('catalog/product')->load($_product->getId());

That will load an instance of the product that contains all the attributes, including the category.

Cheers, JD