On magento, my product pages are showing a white screen. The error printed is Fatal error: Call to a member function getMetaTitle() on a non-object in /app/code/core/Mage/Catalog/Block/Category/View.php on line 44
Here are lines 42-46:
if ($headBlock = $this->getLayout()->getBlock('head')) {
$category = $this->getCurrentCategory();
if ($title = $category->getMetaTitle()) {
$headBlock->setTitle($title);
}
Not sure how to fix this as the code looks fine to me.
Updated code:
if ($headBlock = $this->getLayout()->getBlock('head')) {
$cat_id = $this->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load($cat_id);
if ($title = $category->getMetaTitle()) {
$headBlock->setTitle($title);
}
if ($description = $category->getMetaDescription()) {
$headBlock->setDescription($description);
}
if ($keywords = $category->getMetaKeywords()) {
$headBlock->setKeywords($keywords);
}
if ($this->helper('catalog/category')->canUseCanonicalTag()) {
$headBlock->addLinkRel('canonical', $category->getUrl());
}