Search code examples
phpmagentomagento-1.9

Override Magento Contacts Controller


I'm trying to override Mage/Contacts/IndexController.php

I created a folder in local and created Mynamespace/CustomContacts/controllers/IndexController.php

<?php

require_once 'Mage/Contacts/controllers/IndexController.php';

class Mynamespace_CustomContacts_IndexController extends Mage_Contacts_IndexController {

    protected function indexAction () {
        die;
    }
}

I also put this code in Mynamespace/CustomContacts/etc/config.xml

<config>
    <frontend>
        <routers>
            <contacts>
                <args>
                     <modules>
                        <Mynamespace_CustomContacts before="Mage_Contacts">Mynamespace_CustomContacts</Mynamespace_CustomContacts>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>

I cleaned the cache, but my die; does not work,

Thanks for any help


Solution

  • 1. Best practices

    Your config.xml file seems like this:

    <?xml version="1.0"?>
    <config>
        <modules>
            <Mynamespace_CustomContacts>
                <version>0.1.0</version>
            </Mynamespace_CustomContacts>
        </modules>
        <frontend>
            <routers>
                <contacts>
                    <args>
                        <modules>
                            <Mynamespace_CustomContacts before="Mage_Contacts">Mynamespace_CustomContacts</Mynamespace_CustomContacts>
                        </modules>
                    </args>
                </contacts>
            </routers>
        </frontend>
    </config>
    

    2. Bad practices

    You can move your controller in app/local/Mage/Contacts/controllers/IndexController.php for a hard override.

    And don't forget to enable your module in xml file in app/etc/modules directory