Reputation: 337
I am geting this error only in Chrome, in Firefox everything is fine:
Fatal error: Call to a member function getName() on a non-object in /home1/idealtil/public_html/app/design/frontend/default/blank/template/catalog/product/view.phtml on line 55
here is my code from view.phtml:
<?php
$current_category = Mage::registry('current_category');
if ($current_category->getName() == 'Showroom'): ?> //this is line 55
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
................................. ....................................
what might be the problem?
Upvotes: 2
Views: 325
Reputation: 250
I think you are opening different URL in those browsers. One is opened with and other without category, i.e.
On this second url $current_category would be null .
Could be also that you came from search result page to product and where it lacked category reference in URL.
Upvotes: 1
Reputation: 57418
Your "category" object might be actually null in Chrome, i.e., did you call Mage::register
on current_category
?
Check the URL and call that opens that page, or verify it is not a session issue (e.g. you have data in the Firefox session, but not the Chrome one).
Depending on how you arrived at that page, you might be in an area where current_category
is not (yet?) set by CategoryController::_initCategory()
, because for example the category is not present in the URL. See this answer for some more details. Suppose now that the category is saved in the session and you made several page hits with Firefox. Now the Firefox session does have a cached category available, and when you hit the troublesome cache in Firefox, you see the cache. Then hit that same page with Chrome which has no session or cache available (yet), and that gives you an error.
You may want to wrap the call with some fallback code, to sidestep the problem and not use the category code unless there is indeed a category available:
// Here you might get NULL
$current_category = Mage::registry('current_category');
// If category is **not** NULL, *and* is Showroom, then...
if (($current_category) && ($current_category->getName() == 'Showroom')):
Depending on where you are in the code, you can check more ways of getting the category; see this answer for details.
Upvotes: 2