Magento – Observer event on frontend home page load

event-observermagento-1.9

Is there any observer event on frontend home page load?

On my custom module, I want to display a notice message on home page if certain conditions are met. Can I do this using event-observer?

Best Answer

Add the following in the extension's config.xml

        <events>
        <controller_action_layout_load_before>
            <observers>
                <abandonedcart_observer>
                    <type>singleton</type>
                    <class>abandonedcart/observer</class>
                    <method>showCouponCodeWhenLoad</method>
                </abandonedcart_observer>
            </observers>
        </controller_action_layout_load_before>
    </events>

And here is the code to go in showCouponCodeWhenLoad() function in Observer.php

    $routeName = Mage::app()->getRequest()->getRouteName();
    $identifier = Mage::getSingleton('cms/page')->getIdentifier();

    if($routeName == 'cms' && $identifier == 'home') {
         // do something
    }

Hope this helps to someone!

Related Topic