2

I need to add two methods in two separate Mage/core models. I'm trying to create my own methods in the local code pool, but without any success.

I'm sure the problem lies in my XML file (can't find any reference documentation). The core Mage files reside here:

app->code->core->Mage->Customer->Model->Address->Abstract.php
app->code->core->Mage->Customer->Model->Resource->Customer.php

My own files reside here:

app->code->local->Jongosi->Base->Model->Address->Abstract.php
app->code->local->Jongosi->Base->Model->Resource->Customer.php

My config.xml file looks like this:

<config>
    <global>
        <models>
            <customer>
                <address>
                    <rewrite>
                        <abstract>Jongosi_Base_Model_Address_Abstract</abstract>
                    </rewrite>
                </address>
            </customer>
        </models>
        <models>
            <customer>
                <resource>
                    <rewrite>
                        <customer>Jongosi_Base_Model_Resource_Customer</customer>
                    </rewrite>
                </resource>
            </customer>
        </models>
    </global>
</config>

Could anyone tell me what I'm doing wrong please?

1 Answer 1

6

Let's start with the second. it's easier to explain. To override a resource model your config section should look a little different.

<models>
    <customer_resource><!-- this is the key for a resource model -->
        <rewrite>
            <customer>Jongosi_Base_Model_Resource_Customer</customer>
        </rewrite>
    </customer_resource>
</models>

As for the Address/Abstract.php the simple answer is that you cannot override it like that.
Actually you can, if you now call get_class(Mage::getModel('customer/address_abstract')) you will get the name of the class you just created but this has no effect on the application, because that class is not instantiated in the application. only its children are instantiated.
Even if you overwritten the class the 'children' that are instantiated still extend the original class. I wrote more on this in this article
[Edit] Sorry, I explained the problem but I didn't offer a solution.
You can copy that class from app/code/core/Mage/Customer/Model/Address/Abstract.php to app/code/local/Mage/Customer/Model/Address/Abstract.php but keep it in mind on the next upgrade. There is a chance it will break your Magento instance. I mean, if you upgrade and it breaks, check this file for errors.

1
  • Marius, once again, thx so much.
    – Jongosi
    Commented Jun 5, 2013 at 14:46

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.