Just activated Varnish cache on my magento site and started receiving this error (it worked just fine when Varsnish wasn't active):

Fatal error: Call to a member function getImageUrl() on a non-object in /home/admin/public_html/golulo.es/app/design/frontend/golulo/default/template/page/html/page_header.phtml on line 4

Here is the content from page_header.phtml

    $_helper    = Mage::helper('catalog/output');
    $_category  = Mage::registry('current_category');
    $_imgUrl = $_category->getImageUrl();
    if (!$_imgUrl){
<script type="text/javascript">
<div class="category-header-container">
    <div class="bgback" style="background:#F7F6F4;">
        <div class="container row" style="<?php if($_imgUrl): ?>background-image: url(<?php echo $_imgUrl; ?>);<?php endif; ?>">
            <div class="table-container">
                <div class="category-top-title">
                    <h1><?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></h1>
                <div class="left-area breadcrumbs-holder">
                    <?php echo $this->getChildHtml("breadcrumbs"); ?>
<div class="zn_header_bottom_style"></div>

If I remove $_imgUrl for example, I get the same error with getName.

I'm trying to find any working solution, but I can't find anything that would help.

Any ideas? Thanks,

  • current_category is exist in registry only if the session has requested for some category page.. – Manikandan Arunachalam Jan 7 '15 at 10:10
  • when something is not working only if an extension is activated, then most probably extension makes the problem.. – Manikandan Arunachalam Jan 7 '15 at 10:14
  • I'm trying to contact the developer, I'll update the question when I will have somekind of solution. Thanks. – Artur Rain Jan 7 '15 at 10:31
  • forget about excluding it from cache, just try to load it from another layout and template... – user2857 Jan 13 '15 at 23:15

Mage::registry('current_category'); returns something only if you are on a category page.
I see that you code is in the header. If you are on other pages than a category page $_category will be null so you cannot call different methods on it.

  • Hello, yes you're correct, but this content is only displayed on my category pages, I call it via my local.xml Here's the code: <catalog_category_view> <reference name="top.container"> <block type="core/template" name="page.header" template="page/html/page_header.phtml"> <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/> </block> </reference> </catalog_category_view> – Artur Rain Jan 7 '15 at 10:11
  • In this case it should be OK. Maybe there is a problem with your varnish configuration. – Marius Jan 7 '15 at 10:13
  • Yes, I think so too, because before I've activated Varnish it worked, but now it gives me this error and I have no clue how to fix it. Any ideas what can be happening? I use Turpentime plugin. – Artur Rain Jan 7 '15 at 10:15
  • Maybe you should contact the developer on this – Marius Jan 7 '15 at 10:19
  • Ok, I've added a Issue request on Githud, if some interested here's: Github Issue Link – Artur Rain Jan 7 '15 at 10:24

I've never used Turpentine, but I believe it uses hole punching. If the template in question is hole punched, it's likely unsafe to rely on data in the registry, since it might get rendered without the original action getting processed, and therefore there won't be anything in the registry.

Update: As I say I'm not familiar with how exactly hole-punching works with turpentine, but you could probably try manually loading the category if it isn't in the registry.

$_category  = Mage::registry('current_category');
if ( ! $_category) {
    $categoryId = Mage::app()->getRequest()->getParam('id', false);
    $_category = Mage::getModel('catalog/category')
  • Is there any workarround? – Artur Rain Jan 7 '15 at 10:39
  • I've added an example to my answer. – Peter O'Callaghan Jan 7 '15 at 11:05
  • ok, this made the Error disapear, but still it doesn't retrieve the category name nor breadcrumbs, any ideas? Thank you very much for the help. – Artur Rain Jan 7 '15 at 11:39
  • what extension would you recommend to use? I see that turpentime, gives me a check of a lot problems... Add to cart doesn't work, can't login, all the issues described here etc. – Artur Rain Jan 7 '15 at 12:23

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.