1

I'm trying to load a layout and set my custom phtml after the cart page.

But when I put the directives to load the layout, I have the following error:

Fatal error: Call to a member function getRequestedRouteName() on a non-object in /var/www/html/magento/edubras.dev/html/app/code/core/Mage/Core/Controller/Varien/Action.php on line 226

config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <GrupoNDB_EmailCatcher>
            <version>0.0.1</version>
        </GrupoNDB_EmailCatcher>
    </modules>

    <global>
        <blocks>
            <grupondb_emailcatcher>
                <class>GrupoNDB_EmailCatcher_Block</class>
            </grupondb_emailcatcher>
        </blocks>
        <helpers>
            <grupondb_emailcatcher>
                <class>GrupoNDB_EmailCatcher_Helper</class>
            </grupondb_emailcatcher>
        </helpers>

        <models>
            <grupondb_emailcatcher>
                <class>GrupoNDB_EmailCatcher_Model</class>
            </grupondb_emailcatcher>
        </models>
        <events>
            <controller_action_predispatch_onestepcheckout_index_index>
                <observers>
                    <grupondb_emailcatcher>
                        <class>grupondb_emailcatcher/observer</class>
                        <method>displayEmailCatcherPage</method>
                    </grupondb_emailcatcher>
                </observers>
            </controller_action_predispatch_onestepcheckout_index_index>
        </events>
    </global>
</config>

My observer code:

<?php 

class GrupoNDB_EmailCatcher_Model_Observer {

    public function __construct() {

    }


    public function displayEmailCatcherPage($observer) {

        $frontA = new Mage_Core_Controller_Front_Action;
        $frontA->loadLayout()->getLayout();

        $eCookie = Mage::getModel('core/cookie')->get("email");

        if( $eCookie == 'none'|| !isset($eCookie) || empty($eCookie) ) {
            echo Mage::app()->getLayout()->createBlock('core/template')->setTemplate('grupondb/email-catcher/cadastroEmail.phtml')->toHtml();
            die;
        }

        // Call the block to fill the fields in checkout
        echo Mage::app()->getLayout->createBlock('core/template')->setTemplate('grupondb/email-catcher/set-email-field.phtml')->toHtml();


    }

}

Someone can help me with this?

Cheers!

2

You should not use the Mage_Core_Controller_Front_Action this way and actually you don't need an observer for this at all.

Layout changes can be done via the layout xml files in app/design/frontend/YOURPACKAGE/YOURTHEME/layout/.

The standard layout file from the rwd theme is app/design/frontend/rwd/default/layout/checkout.xml.

You can update the template for a specific page and add the relevant part to your app/design/frontend/YOURPACKAGE/YOURTHEME/layout/local.xml

<checkout_onepage_index translate="label">
    <reference name="checkout.onepage">
        <block type="grupondb_emailcatcher/YOURBLOCKCLASS" name="checkout.emailcatcher.cadastroemail" as="cadastroemail" template="grupondb/email-catcher/cadastroEmail.phtml"/>
        <block type="grupondb_emailcatcher/YOURBLOCKCLASS" name="checkout.emailcatcher.setemailfield" as="setemailfield" template="grupondb/email-catcher/set-email-field.phtml"/>
    </reference>
</checkout_onepage_index>

Please note:

  • You also need to create the corresponding block classes to use this.
  • You did not mention where exactly you would like to insert your blocks so you might need to adjust either checkout_onepage_index or the reference name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.