2

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.

2
  • 1
    I also need help in this Commented Feb 7, 2015 at 9:48
  • The same way as you would rewrite any other model. What did you try? Commented Feb 12, 2015 at 9:07

1 Answer 1

2

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).

3
  • @PratikBhatt, above is how you could override the model. I can't understand from your question what further problems you exactly run into (extending a PHP class?). Please update your question if you have any other problems regarding overriding this model.
    – 7ochem
    Commented Feb 12, 2015 at 8:56
  • @70Chem I tried this but this does not call my new model and just calls the previous one. Commented Feb 13, 2015 at 9:32
  • 1
    @Pratikbhatt you could trace back the calls to the methods of the Customweb_PostFinanceCw_Model_OrderContext class and see how it is called. Sometimes I see extensions where they instantiate the class directly: $instance = new Customweb_PostFinanceCw_Model_OrderContext() instead of Mage::getModel(...). So then overriding will never work...
    – 7ochem
    Commented Feb 13, 2015 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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