huguesalary / Magento-Varnish

This Magento extension provides a Real Full Page Caching for Magento powered by Varnish with support of Session-Based information caching (Cart, Customer Accounts, ...) via ESI includes
Other
95 stars 18 forks source link

cache welcome message #17

Closed ed29 closed 11 years ago

ed29 commented 11 years ago

Magento Varnish cache the welcome message,it's a problem;change to per-client mode would be good.

huguesalary commented 11 years ago

Hi,

It seems that the welcome message has been hard coded in a Block file: app/code/Core/Mage/Page/Block/Html/Header.php making impossible to make it an esi block by default. That's a typical Magento "WTF? moment".

One way to solve this problem is to create a new block that will contain your welcome message.

Edit your local.xml file, add something like:

<reference name="header">
        <block type="page/html" name="my_welcome_message" template="my_module/my_welcome_message.phtml">
            <action method="setEsi">
                <params>
                    <cache_type>per-client</cache_type>
                </params>
            </action>
        </block>
</reference>

Create a template file in my_module/my_welcome_message.phtml:

<?php 
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
echo $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName()));
}
?>

then, in app/design/frontend/your_package/your_theme/template/page/html/header.phtml , find the line saying <?php echo $this->getWelcome() ?> and replace it by <?php echo $this->getChildHtml("my_welcome_message") ?>

geetikatina commented 6 years ago

Its really help full for me and working also.Thanks