2

I have followed few instructions found in this forum, but I must be missing something. I am trying to override Contacts controller, specifically postAction method. Here is what I have got:

Magento version: 1.9.3.1;
Namespace: MageOverload;
Module: ContactsModule;

/app/code/local/MageOverload/ContactsModule/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <MageOverload_ContactsModule>
            <version>1.0.0</version>
        </MageOverload_ContactsModule>
    </modules>
    <frontend>
        <routers>
            <contactsmodule>
                <args>
                    <modules>
                        <MageOverload_ContactsModule before="Mage_Contacts">MageOverload_ContactsModule</MageOverload_ContactsModule>
                    </modules>
                </args>
            </contactsmodule>
        </routers>
    </frontend>
</config>

/app/etc/modules/MageOverload_ContactsModule.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <MageOverload_ContactsModule>
            <active>true</active>
            <codePool>local</codePool>
        </MageOverload_ContactsModule>
    </modules>
</config>

/app/code/local/MageOverload/ContactsModule/controllers/IndexController.php:

<?php
require_once Mage::getModuleDir('controllers', 'Mage_Contacts') . DS . 'IndexController.php';
class MageOverload_ContactsModule_IndexController extends Mage_Contacts_IndexController
{
    public function postAction() {
        //... custom code
    }
}

I have flushed cache, custom module is visible via magento admin panel, but still the system is using Mage core files for Contacts. Any help would be greatly appreciated.

2
  • magento.stackexchange.com/questions/70965/… - I have followed these instructions, but still the problem occurs.
    – Kuba M
    Commented Jul 10, 2017 at 8:45
  • Try changing your package name to Mageoverload and module name to Contactsmodule and update folder names and class names as per.
    – John
    Commented Jul 10, 2017 at 9:03

2 Answers 2

3

Your controller rewrite XML part should look like this:

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

As you can see instead of using <contactsmodule> node we are here using <contacts> node. <contacts> is the router node which is using by Mage_Contacts module.

After this change is done, do not forget to flush the cache again.

Free Tip:

It is a good practice to keep dependency in your module as shown below.

File : MageOverload_ContactsModule.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MageOverload_ContactsModule>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Contacts />
            </depends>
        </MageOverload_ContactsModule>
    </modules>
</config>

This clearly indicates that, your module has a dependency on Mage_Contacts module and thus Magento will load your module only after Mage_Contacts is loaded.

1
  • 1
    Thank You very much. Your answer is more than I expected. All the best for You!
    – Kuba M
    Commented Jul 10, 2017 at 9:37
0

Please try the below code.

app\etc\modules\MageOverload_ContactsModule.xml

<?xml version="1.0"?>
<config>
  <modules>
    <MageOverload_ContactsModule>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </MageOverload_ContactsModule>
  </modules>
</config>

app\code\local\MageOverload\ContactsModule\etc\config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <MageOverload_ContactsModule>
      <version>0.1.0</version>
    </MageOverload_ContactsModule>
  </modules>
  <frontend>
    <routers>
      <contactsmodule>
        <use>standard</use>
          <args>
            <module>MageOverload_ContactsModule</module>
            <frontName>contactsmodule</frontName>
          </args>
      </contactsmodule>
    </routers>
  </frontend>
  <global>
        <rewrite>        
            <mageoverload_contactsmodule_contacts_indexcontroller>
                <from><![CDATA[#^/contacts/index/#]]></from> <!-- Mage_Contacts_IndexController  -->
                <to>/contactsmodule/contacts_index/</to> <!-- MageOverload_ContactsModule_Contacts_IndexController  -->
            </mageoverload_contactsmodule_contacts_indexcontroller>
        </rewrite>

  </global>  
</config> 

app\code\local\MageOverload\ContactsModule\controllers\Contacts\IndexController.php

require_once "Mage/Contacts/controllers/IndexController.php";  
class MageOverload_ContactsModule_Contacts_IndexController extends Mage_Contacts_IndexController{

    public function postAction()
    {
       //custom code
    }


}

Hope it will help you.

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.