how to not cache the footer in magento

With some advanced scheduled-post-voodoo i successfully managed to publish this post already yesterday with some completely unrelated queries and no text. this was not intended – please accept my apologies :P

Anyway: In the footer of my magento shop we might have a summary of the shopping cart,
which i simply put in the footer.phtml template file:

<?php if (Mage::getModel('checkout/cart')->getItemsCount() > 0): ?>
<div class="footer_cart_widget">
<a href="/checkout/cart" class="cart">
<?php echo $this->__('Warenkorb') ?>:<br />
<span class="cart_meta">
<?php echo Mage::getModel('checkout/cart')->getItemsCount() ?>
<?php if (Mage::getModel('checkout/cart')->getItemsCount() == 1): ?>
Produkt: 
<?php else: ?>
Produkte: 
<?php endif; ?>
<?php echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); ?>
</span>
</a>
</div>
<?php endif; ?>

Magento Footer Shopping cart Widget disable cache

This means we might need to disable the caching for the footer HTML block,
so that my cart summary will stay dynamically generated.

This is how you can do it:

copy

app/code/core/Mage/Page/Block/Html/Footer.php

to

app/code/local/Mage/Page/Block/Html/Footer.php

and just comment out the following lines:

//$this->addData(array(
//    'cache_lifetime'=> false,
//    'cache_tags'    => array(Mage_Core_Model_Store::CACHE_TAG, Mage_Cms_Model_Block::CACHE_TAG)
//));

you could also put the cart values in the getCacheKeyInfo() method, but as this would result in caching a footer for any state of the shopping cart from my understanding, i don’t think it’s necessarily a good idea.

6 Replies to “how to not cache the footer in magento”

  1. Thanks so much for pointing out that issue I thought i would have to re-write my session variable code.
    Quick easy fix, worked well.

  2. If you do what cayen said, by changing the type in the page.xml to “core/template” you will find that the echo $this->getCopyright() PHP will no longer work.
    So the correct way to do it is as above by making a local version of a core file.

Leave a Reply

Your email address will not be published. Required fields are marked *