6

I am trying to rewrite an observer in the extensions Xtento_GridActions. The observer is established this way:

        <core_block_abstract_prepare_layout_after>
            <observers>
                <addMassactionsToGrid>
                    <type>model</type>
                    <class>Xtento_GridActions_Model_Observer</class>
                    <method>core_block_abstract_prepare_layout_after</method>
                </addMassactionsToGrid>
            </observers>
        </core_block_abstract_prepare_layout_after>

I have created my rewrite class at app/code/local/Mymod/Orders/Model/Xtentorewrite/Observer.php and it looks like this:

class Mymod_Orders_Model_Xtentorewrite_Observer extends Xtento_GridActions_Model_Observer {

    /*
     * Get controller names where the module is supposed to modify the block
     */
    public function getControllerNames()
    {
        die('here');
        $originalArray=array('order', 'sales_order', 'adminhtml_sales_order', 'admin_sales_order', 'orderspro_order');
        $newOrdersController="orders"; 
        $modifiedArray=$originalArray;
        $modifiedArray[]=$newOrdersController;
        return $modifiedArray;
    }
}

My config.xml looks like this

 <?xml version="1.0"?>
 <config>
<modules>
    <Mymod_Orders>
        <version>0.1.5</version>
    </Mymod_Orders>
</modules>
<global>
    <models>
        <mymodorders>
            <class>Mymod_Orders_Model</class>
        </mymodorders>
        <xtento_gridactions>
            <rewrite>
                <observer>Mymod_Orders_Model_Xtentorewrite_Observer</observer>
            </rewrite>
        </xtento_gridactions>
    </models>
    <blocks>
        <orders>
            <class>Mymod_Orders_Block</class>
        </orders>
    </blocks>
</global>
<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Mymod_Orders before="Mage_Adminhtml">Mymod_Orders</Mymod_Orders>
                </modules>
            </args>
        </adminhtml>
    </routers>

</admin>
<crontab>
    <jobs>
        <Mymod_Fetch_Unpaid_Orders_Report>
            <schedule>
                <cron_expr>0 5 * * 1,2,3,4,5</cron_expr>
                <!-- Run on weekdays (1-5) at 5 am -->
            </schedule>
            <run>
                <model>mymodorders/fetchorderinfo::mailReport</model>
            </run>
        </Mymod_Fetch_Unpaid_Orders_Report>
    </jobs>
</crontab>

5

You can override observers easily.

In your own module add this to your config xml events area

    <core_block_abstract_prepare_layout_after>
        <observers>
            <addMassactionsToGrid>
                <type>model</type>
                <class>mymod_orders/xtentorewrite_observer</class>
                <method>core_block_abstract_prepare_layout_after</method>
            </addMassactionsToGrid>
        </observers>
    </core_block_abstract_prepare_layout_after>

It might be worthwhile reading through this: http://www.atwix.com/magento/overriding-observers/

Also, you can see that you should not give the full class name. Give the magento alias!

  • 1
    In addition You just have to make sure that your module depends on the original module so is loaded after it. – Marius Jun 30 '15 at 9:02
  • This doesn't answer the question. What you've provided here is how one can add their own observer to the same event, not how one can override the functionality of an existing observer. The link, however, does have details on how you overwrite an observer in various cases. – BrianVPS Apr 4 at 19:36
  • 1
    @BrianVPS nope. By using the same XML path, making your module depend on the Xtento_GridActions module, and making your observer extend the Xtento_GridActions_Model_Observer class it will cause your logic to trigger rather than the Xtento_GridActions module. – Luke Rodgers Apr 5 at 7:04
  • @LukeRodgers I was not aware it worked that way, thanks for the clarification. I'll have to give that a shot. – BrianVPS Apr 16 at 14:49

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.