1

I am trying to override

Mage/Core/Model/Domainpolicy.php

Currently I have done it successfully by copying it to:

app/code/local/Mage/Core/Model/Domainpolicy.php

and added my modifications. That works fine.

But instead I would prefer to have it in my own module which is structured as follows:

app/code/local/Me/Mymodule/

and in its config.xml I have:

<?xml version="1.0"?>
<config>
    <modules>
        <Me_Mymodule>
            <version>0.1</version>
        </Me_Mymodule>
    </modules>
    <global>
        <models>
            <core>
                <rewrite>
                    <domainpolicy>Me_Mymodule_Core_Model_Domainpolicy</domainpolicy>
                </rewrite>
            </core>
            <reports_resource>
                <rewrite>
                    <helper_mysql4>Me_Mymodule_Reports_Model_Resource_Helper_Mysql4</helper_mysql4>
                </rewrite>
            </reports_resource>
        </models>
        <blocks>
            <page>
                <rewrite>
                    <html_head>Me_Mymodule_Page_Block_Html_Head</html_head>
                </rewrite>
            </page>
        </blocks>
    </global>
    <frontend>
        <routers>
            <contacts>
                <args>
                    <modules>
                        <Me_Mymodule before="Mage_Contacts">Me_Mymodule_Contacts</Me_Mymodule>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

In app/code/local/Me/Mymodule/Core/Model/Domainpolicy.php I have:

class Me_Mymodule_Core_Model_Domainpolicy extends Mage_Core_Model_Domainpolicy

and the original original code with my modifications applied in one of the functions (I just add a few HTTP headers to the original content policy, no any big changes).

The problem is that when I move the modified Domainpolicy.php inside my module and extend the original class as shown (and it is no longer in app/code/local/Mage) Magento doesn't use it but runs the original one (from app/code/core). At the same time all other things which you see I have overriden in the same module work as expected.

What am I missing?

1 Answer 1

3

Your rewrite is not correct, plus you should put the 'core' folder with the 'Model' folder

In config.xml

<global>
    <models>
        <core>
            <rewrite>
                <domainpolicy>Me_Mymodule_Model_Core_Domainpolicy</domainpolicy>
            </rewrite>
        </core>

Path

 app/code/local/Me/Mymodule/Model/Core/Domainpolicy.php

Class

 class Me_Mymodule_Model_Core_Domainpolicy extends Mage_Core_Model_Domainpolicy
1
  • I have done what you suggest but still doesn't work. When rewriting Reports_Model_Resource_Helper_Mysql4 I didn't need put it in app/code/local/Me/Mymodule/Model but it is directly in app/code/local/Me/Mymodule/Reports/Model/Resource/Helper/Mysql4.php. Could you please explain why in this case I need to create a reversed Model/Core directory. Shouldn't it keep the original directory tree which in app/code/core/Mage is Core/Model?
    – george
    Feb 15, 2015 at 9:29

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.