12

I need to override a method Controller

Core/Mage/Customer/controllers/AccountController.php 

and add a new method. Since this controller to edit is wrong - it should be overridden.

According to the project requirements override the controller must be at

local/New/Mage/Customer/controllers/AccountController.php 

To do this, create a file config, but addresses customer/account/test, customer/account /ajax did not respond, and customer/account/login It is not overridden. Please help in this implementation.

app/app/etc/modules/New_Mage_Customer.xml

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

app/code/local/New/Mage/Customer/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <New_Mage_Customer>
            <version>0.0.1</version>
        </New_Mage_Customer>
    </modules>
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <new_customer before="Mage_Customer">New_Mage_Customer</new_customer>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>

app/code/local/New/Mage/Customer/controllers/AccountController.php

<?php

/**
 * Customer account controller
 */
require_once 'Mage/Customer/controllers/AccountController.php';

class New_Mage_Customer_AccountController extends Mage_Customer_AccountController {

    public function ajaxAction() {
        echo 'ajax!!';
    }

    public function testAction() {
        echo 'test222';
    }

    public function loginAction() {
        echo 'index';
    }

}

Thanks!

1

1 Answer 1

22

The file name will be app/etc/modules/New_Mage.xml

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

In app/code/local/New/Mage/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <New_Mage>
            <version>0.0.1</version>
        </New_Mage>
    </modules>
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <New_Mage before="Mage_Customer">New_Mage</New_Mage>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>

controller will app/code/local/New/Mage/controllers/AccountController.php

/**
 * Customer account controller
 */
require_once Mage::getModuleDir('controllers', 'Mage_Customer') . DS . 'AccountController.php';

class New_Mage_AccountController extends Mage_Customer_AccountController {

    public function ajaxAction() {
        echo 'ajax!!';
    }

    public function testAction() {
        echo 'test222';
    }

    public function loginAction() {
        echo 'index';
    }

}

Reference

1
  • Will this not override all customer requests, including example.com/customer/address/new/? and if there is no address controller in this new module, all /customer/address/* requests will now 404 Commented Jan 28, 2019 at 21:32

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.