1

There is an observer in core module which is being called on sales_order_place_after event. I want it to call it for sales_order_save_after event. How do I override the config.xml file to change the event call name.

2

I don't know why you want to do it so I cannot judge if it makes sense but as a heads up: this will have lots of side effects that you probably are not aware of, so be cautious!

Now for the technical answer: you cannot override the XML file but you can override individiual settings in a custom module because all config.xml files are merged into one structure.

For configuration files there is no way to remove previous nodes (the sales_place_order_after observer), but it's possible to change the type of an observer:

So let's say the original observer is

<events>
    <sales_order_place_after>
        <observers>
            <salesrule>
                <class>salesrule/observer</class>
                <method>sales_order_afterPlace</method>
            </salesrule>
        </observers>
    </sales_order_place_after>
</events>

Then you can set the type of the salesrule observer to disabled in your own config:

<events>
    <sales_order_place_after>
        <observers>
            <salesrule>
                <type>disabled</type>
            </salesrule>
        </observers>
    </sales_order_place_after>
</events>

and then define a new observer for sales_order_save_after:

<events>
    <sales_order_place_after>
        <observers>
            <salesrule>
                <type>disabled</type>
            </salesrule>
        </observers>
    </sales_order_place_after>

    <sales_order_save_after>
        <observers>
            <salesrule>
                <class>salesrule/observer</class>
                <method>sales_order_afterPlace</method>
            </salesrule>
        </observers>
    </sales_order_save_after>
</events>

Note that module loading order is important for overrides, so your module must be loaded after the original module. Since it is a core module, this is already the case. Core modules are always loaded before community/local modules.

If it were not a core module, you would have to define a dependency in your app/etc/modules module activation file. But it's good practice to always make dependencies explicit:

<depends>
    <Mage_SalesRule />
</depends>
| improve this answer | |
  • Thank you for the answer. I had to add depends tag for it to work. – Twinkal Jul 12 '16 at 7:07
  • Weird, if yours is a local module, the core module should always be loaded first. I extended the answer anyways. – Fabian Schmengler Jul 12 '16 at 7:12
0

You need to create one more module:

Global Configuration file should look like:

<?xml version="1.0"?>
<config>
<modules>
    <Namespace_Newmodule>
        <codePool>local</codePool>
        <active>true</active>
        <depends>
            <Namespace_Oldmodule />
        </depends>
    </Name_Newmodule>
</modules>

After doing this your new module config.xml file will call first. If both observer is calling this way then you need to comment the event sales_order_place_after code from old module.

| improve this answer | |

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.