Magento – How to override Magento model file that extends PHP class

magento-1magento-1.9modelmoduleoverrides

I want to override a model file of another extension into my extension in order to develop the compatibility between the two extensions

The class I want to override is class Customweb_PostFinanceCw_Model_OrderContext extends Customweb_Payment_Authorization_OrderContext_AbstractDeprecated implements Customweb_Payment_Authorization_IOrderContext this class also extends another class of PHP

Please help me in extending this file.

Best Answer

Below a simple example of how to override a model from one module within another module.

Please take a look at the file app/code/local/Customweb/PostFinanceCw/etc/config.xml for the correct use of the modulename namespace (which I can't read from your question, I used customweb_postfinancecw for now).

You'd have to have a piece of XML like this in your module's config.xml (I named it MyCompany_MyModule, please replace it with your own)

<config>
    <global>
        <models>
            <mycompany_mymodule>
                <class>MyCompany_MyModule_Model</class>
            </mycompany_mymodule>
            <customweb_postfinancecw>
                <rewrite>
                    <ordercontext>MyCompany_MyModule_Model_OrderContext</ordercontext>
                </rewrite>
            </customweb_postfinancecw>
        </models>
    </global>
</config>

Then, in app/code/local/MyCompany/MyModule/Model/, create a file OrderContext.php like this

class MyCompany_MyModule_Model_OrderContext extends Customweb_PostFinanceCw_Model_OrderContext
{

    /* Override methods now */

}

You should name the methods exactly the same as in the original Customweb_PostFinanceCw_Model_OrderContext class to override it's functionality. Also keep in mind to keep the same visibility (public, protected or private).

Related Topic