Lesti::Fpc – Magento 1.7 and the Welcome Message

The Welcome Message in Magento 1.7 is a problem for Lesti::Fpc. You can find the reason in app/design/frontend/base/default/template/page/html/header.phtml.

<!-- ... -->
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
<!-- ... -->

The welcome message is just a function of the header block. Lesti::Fpc needs the welcome message in a seperated block. In Magento 1.8 this is solved and the name of the block is welcome. In Magento 1.7 there is a semi-solution in core, we just have to give a little help.

Were to find Welcome Message Block in Magento 1.7

The welcome message block in Magento 1.7 exists, but it isn’t used. You can find the block under app/code/core/Mage/Page/Block/Html/Welcome.php. In Magento 1.8 this block has the full functionallity for the welcome message, but in Magento 1.7 the block just repeats the function of the header.

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Page
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 
/**
 * Html page block
 *
 * @category   Mage
 * @package    Mage_Page
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Page_Block_Html_Welcome extends Mage_Core_Block_Template
{
    /**
     * Get block messsage
     *
     * @return string
     */
    protected function _toHtml()
    {
        return Mage::app()->getLayout()->getBlock('header')->getWelcome();
    }
}

Why we can’t use this welcome block?

That isn’t good for Fpc. Cause the Fpc builds a minimal layout for the dynmaic and lazy blocks before it replaces the placeholders and sends response to the customer. And the Fpc just takes the dynamic and lazy blocks in this layout to reduce the time to build layout. But if the welcome block needs the header block to get the welcome message the layout can’t give the header block. So we have to build the welcome block like Magento 1.8 does. The easiest way is just to copy the source from Magento 1.8 and to copy it into community-pool (not the recommended way). The source of app/code/community/Mage/Page/Block/Html/Welcome.php.

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Page
 * @copyright   Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
 
/**
 * Html page block
 *
 * @category   Mage
 * @package    Mage_Page
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Page_Block_Html_Welcome extends Mage_Core_Block_Template
{
    /**
     * Get block messsage
     *
     * @return string
     */
    protected function _toHtml()
    {
        if (empty($this->_data['welcome'])) {
            if (Mage::isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) {
                $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName()));
            } else {
                $this->_data['welcome'] = Mage::getStoreConfig('design/header/welcome');
            }
        }
 
        return $this->_data['welcome'];
    }
 
    /**
     * Get tags array for saving cache
     *
     * @return array
     */
    public function getCacheTags()
    {
        if (Mage::getSingleton('customer/session')->isLoggedIn()) {
            $this->addModelTags(Mage::getSingleton('customer/session')->getCustomer());
        }
 
        return parent::getCacheTags();
    }
}

You just have to edit your layout.xml. [path_to_your_theme]/layout/page.xml.

<?xml version="1.0"?>
<!-- ... -->
<layout version="0.1.0">
    <!-- ... -->
    <default>
        <!-- ... -->
        <reference name="header">
            <block type="page/html_welcome" name="welcome" as="welcome"/>
        </reference>
        <!-- ... -->
    </default>
    <!-- ... -->
</layout>

Now just replace in [path_to_your_theme]/template/page/html/header.phtml.

<?php echo $this->getWelcome() ?>

with

<?php echo $this->getChildHtml('welcome') ?>

and everything is fine if you have welcome as a lazy block in your configurations.

27 thoughts on “Lesti::Fpc – Magento 1.7 and the Welcome Message”

    1. Actually I has made all the steps, flushed caches, etc. But now don’t show any welcome message. I am using magento 1.7.0.2

      I checked all the steps twice and I think that all is exactly as appears in this post.

  1. Thank you very much for this elaborate explanation and fix. I’ve implemented it succesfully in a 1.7.0.2 instance. Actually I chose to not put an override in the community pool, since I see this as a picked cherry from 1.8. So I just made the change in the core pool which will be overwritten again during an upgrade. Would I have made an override in community pool, it might interfere with changes in regard to the welcome message in future core releases.

  2. Greetings,

    My theme only has local.xml in the layout folder. I m reffering for this step of the process.
    ” You just have to edit your layout.xml. [path_to_your_theme]/layout/page.xml.
    ….etc.

    Could you be more specific about the file i need to edit ?
    Also if i modify the local.xml where i actually found ” ” one refresh out of two on a main category page the website remains blank(white page no content) next refresh the page loads.
    Even so FPC still chaches the page with the welcome x customer .

    Thank you

    1. If your layout just have a local.xml, you can also use this. It’s the same, cause the files will be merged. If you have a blank page, I would take a look at the error.log of your webserver.

  3. Hello, i have the same issue as @INCO.
    My theme does not have any page.xml. The big problem is the blank screen but, even so, if you do a refresh the page appears. And it seem to be CACHED. So nothing solved. Anyway i was looking into ERORR logs and no error at that hour i tested this.

    We must find a solution….

    With respect,
    Shanaki

  4. Hello ,

    After further attempts i realized that the actual code works ( when i say works i mean it actually does the echo ‘welcome your_name’. The problem with the blank page with no content only happens after i include welcome in fpc configuration in the lazy blocks and it only displays blank page at first try if you are not logged in. If you are logged in it displays the page at first try BUT there is no echo welcome if the page was previously cached by another user. If the page wasn’t cached previously by another user the echo works.

      1. Also had this issue of the Welcome showing on the 1st Page but the cached page does not. The only way I could get to work was by adding “welcome” to the Dynamic blocks and removing fron the Lazy Blocks.

  5. Hello Gordon! I am new to Magento and I have bumped into the welcome issue on version 1.7 and have tried the solution above without too much luck. Since I could not get it to work I have removed the welcome message from the lazy block completely. Will that cause any trouble? Thanks!

    1. If you removed the welcome message from dynamic blocks, it will happen, that User A sees the Welcome Message of User B and User A will go away and will never buy anything, cause he thinks you have security leak.

  6. Only removed it from lazy blocks on the admin panel for your app as a “try and see what happens”. It seems (I have probably reate another problem however i have not yet figured it out) to have resolved the poblem. It is important to noe that I have tried the page.xml adjustment mentioned above and have only removed the welcome message from the lazy block as a last resort. So far so good.

  7. Fatal error: Call to a member function getWelcome() on a non-object in /html/includes/src/Mage_Page_Block_Html_Welcome.php on line 43

    i added getChildHtml(‘welcome’) ?> in my themes header.phtml and my theme has a local.xml file with

    I really want to speed up our magento store can you help?!

  8. I have fpc enabled and I noticed on certain categorys our manadev filter navigation has random attributes enabled and i can not clear them? Do i need to add the manadev as dynamic?

  9. Does not work with compilation enabled? Fatal error: Call to a member function getWelcome() on a non-object in /html/includes/src/Mage_Page_Block_Html_Welcome.php on line 43

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>