2

I'm trying to override the model Mage_Core_Model_Domainpolicy. Everything should work by now, but, obviously, it doesn't. This is my config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <My_Module>
            <version>1.0.0</version>
        </My_Module>
    </modules>
    <global>
        <models>
            <core>
                <rewrite>
                    <domainpolicy>My_Module_Model_Domainpolicy</domainpolicy>
                </rewrite>
            </core>
        </models>
    </global>
</config>

My overriding class(app/code/local/My/Module/Model/Domainpolicy.php):

<?php

class My_Module_Model_Domainpolicy extends Mage_Core_Model_Domainpolicy {

    /**
     * Get frontend policy
     *
     * @return string|null
     */
    public function getFrontendPolicy() {
        return null;
    }

}

And here my module xml file:

<?xml version="1.0"?>
<config>
    <modules>
        <My_Module>
            <active>true</active>
            <codepool>local</codepool>
        </My_Module>
    </modules>
</config>

I've checked it a thousand times, but still NO clue what I'm doing wrong..

  • check compiler enable or not?Or Clear Cache – Amit Bera Apr 14 '15 at 12:19
  • Compiler and cache is completely disabled, deleted cache, locks and tmp in the var folder. – Timon de Groot Apr 14 '15 at 12:28
3

Your override might be correct. But look at this:

app/code/core/Mage/Core/etc/config.xml:158

<security_domain_policy>
    <class>Mage_Core_Model_Domainpolicy</class>
    <method>addDomainPolicyHeader</method>
</security_domain_policy>

The class is hardcoded. So an override of the model will not work. The only way to override this class is to include the same class in the app/code/local folder.

6

So as pointed out via another comment the class has been hardcoded in the event.

<events>
    <controller_action_predispatch>
        <observers>
            <security_domain_policy>
                <class>Mage_Core_Model_Domainpolicy</class>
                <method>addDomainPolicyHeader</method>
            </security_domain_policy>
        </observers>
    </controller_action_predispatch>
</events>

But this is not the end of the world what you can do is rewrite the config.xml here with your own config.xml.

Since the xml is Magento is merged you can do the following.

Add a depends node to Module xml so that the config.xml is loaded in the correct order.

<?xml version="1.0"?>
<config>
    <modules>
        <My_Module>
            <active>true</active>
            <codepool>local</codepool>
            <depends>
                <Mage_Core/>
            </depends>
        </My_Module>
    </modules>
</config>

Now when you work on your config xml you can add the snippet.

<global>
        <events>
        <controller_action_predispatch>
            <observers>
                <security_domain_policy>
                    <class>Your_Class_Here</class>
                </security_domain_policy>
            </observers>
        </controller_action_predispatch>
    </events>
</global>

Now you can either hardcode the class name yourself or what I would do is use core/domainpolicy and then the normal config rewrite will work as expected.

  • +1, because this is what I want to add with @janw's answer. two questions. 1) still we cannto rewrite the method Mage_Core_Model_Domainpolicy::addDomainPolicyHeader() with this configuration, right ? 2)I can't see method node inside your code. Only class defined. In that case, which default method get called ? – Rajeev K Tomy Apr 20 '15 at 7:57
  • @RajeevKTomy sure you can rewrite the method it is the same as a normal rewrite simply extend the base class and you can do what you like. Also you do not need the method node as you are not changing the method being called. – David Manners Apr 20 '15 at 7:59
  • I think I didnt get the first point. This is my understanding on events. "Magento will execute the method specified in the observer class in the loading order of modules once a specific event is dispatched." If that is the case, Mage_Core_Model_Domainpolicy::addDomainPolicyHeader() will get executed then it will execute My_Module_Model_Observer::addDomainPolicyHeader(). My point is first method is also executing rather than skipping it ! Am I right ? – Rajeev K Tomy Apr 20 '15 at 8:05
  • if we make Mage_Core module depend on our module, then first priviledge for our module. This way we will get full access to do anything over the class Mage_Core_Model_Domainpolicy. What would you think about that ? – Rajeev K Tomy Apr 20 '15 at 8:09
0

you have to define your model classname as well with global tag

<global>
    <models>
        <my_module>
            <class>My_Module_Model</class>
        </my_module>

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

hope this will work for you

  • 1
    He means that you forgot model class declaration in your config <my_module><class>My_Module_Model</class></my_module> – zhartaunik Apr 14 '15 at 12:28
  • Oh that's what I did: <my_module><class>My_Module_Model_Domainpolicy</class></my_module> – Timon de Groot Apr 14 '15 at 12:33
  • It didn't work, unfortunately! :/ – Timon de Groot Apr 14 '15 at 12:50
  • try to check with get_class function to see which class is used currently in your file – liyakat Apr 14 '15 at 12:52
  • This is what I have at the moment: gist.github.com/Desmaster/40327a4c48be90e242c1 – Timon de Groot Apr 14 '15 at 13:00
0

Create new file in magento root with the following code and show us the result

<?php

require_once("app/Mage.php");
umask(0);
Mage::app();

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
Mage::init();

$object = Mage::getModel('core/domainpolicy');
$rewrite = (string)Mage::getConfig()->getNode()->global->models->core->rewrite->domainpolicy;
$active = (string)Mage::getConfig()->getNode()->modules->Zhartaunik_Test->active;

echo "Object: " . get_class($object) . "<br />";
echo "Rewrite: " . $rewrite . "<br />";
echo "Is Active: " . (string)$active  . "<br />";

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.