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.