2

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?

Artur Klassen
  • 337
  • 2
  • 9
  • 1
    You get a PHP error only in Chrome? This means there would be some browser specific code in Magento - or you are wrong. Or there is some Javascript that only gets executed in Chrome... – djot Sep 21 '13 at 15:21
  • 2
    Don't mistake a stuck browser cache for a difference in code execution between browsers. – Fiasco Labs Sep 21 '13 at 17:28

2 Answers2

2

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.

Community
  • 1
  • 1
LSerni
  • 55,617
  • 10
  • 65
  • 107
  • hi! sorry, what did you mean by "did you call Mage::register on current_category?" this: $current_category = Mage::registry('current_category'); – Artur Klassen Sep 21 '13 at 17:21
  • and what is session issue? could you explain, please? I am not sure how to fix it. – Artur Klassen Sep 21 '13 at 17:24
  • `current_category` is *not* automatically set in all pages. Where it is not, you either set it yourself (if it is really needed), or it will be NULL -- giving the error you have. I'll expand my answer, though. – LSerni Sep 21 '13 at 19:10
  • great! Thank you very much for such clear answer. It worked!! – Artur Klassen Sep 30 '13 at 16:09
1

I think you are opening different URL in those browsers. One is opened with and other without category, i.e.

  1. http://example.com/cool-category/coolest-product

  2. http://example.com/coolest-product

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.

Elvin Risti
  • 250
  • 2
  • 6