0

I am trying to change the title of a new tab depending on the category ID of the product and I am getting this error message and i cant figure out why

Fatal error: Call to a member function getId() on a non-object in /home/senorehe/public_html/app/code/local/Mage/Catalog/Helper/Data.php

I know it is telling me what the problem is but i dont know why it is occurring as it works on my test server. This is my code which i have in Mage/Catalog/Helper/Data.php

 public function getTabName(){
    $currentCategoryId = Mage::registry('current_category')->getId(); 

    if ($currentCategoryId == '1168' || $currentCategoryId == '1169' || $currentCategoryId == '1174' || $currentCategoryId == '1175' || $currentCategoryId == '1177') 
    {
        return 'Size Guide'; 
    }
    return $this->__('Data Sheets');
}

and this is the local.xml code

<action method="addTab" translate="title" module="catalog" >    
    <alias>pdf_tabbed</alias>
    <title helper="Catalog/getTabName" />
    <block>catalog/product_view_attributes</block>
    <template>catalog/product/view/pdf.phtml</template>
</action>
1

Instead of

$currentCategoryId = Mage::registry('current_category')->getId();

use this

$currentCategoryId = null;
if (Mage::registry('current_category')) {
     $currentCategoryId = Mage::registry('current_category')->getId();
}
| improve this answer | |
  • Thank you, i will accept when it lets me. So what was the reason for the error and why did your fix work, just so i know for the future – Adam Allen Nov 24 '15 at 13:09
  • sometimes, depending on the url Mage::registry('current_category') returns null. – Marius Nov 24 '15 at 13:13

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.