Remove fields from customer adminhtml tab

1.3k Views Asked by At

I am trying to remove two fields from appearing in the Magento adminhtml > Customers > Manage Customers > Customer Information > Account Information tab and cannot seem to get Magento to recognize what I've done. (At least, not that I can see.)

In my custom module that I want to include the override, I have:

file: app/code/community/MyCompany/Profile/Block/Adminhtml/Customer/Edit/Tab/Account.php

class MyCompany_Profile_Block_Adminhtml_Customer_Edit_Tab_Account
    extends Mage_Adminhtml_Block_Customer_Edit_Tab_Account
{
    public function initForm()
    {
        die('My module adminhtml block loaded!');
    }
 }

Once I can confirm that the above initForm() method is getting called, I will then modify it to remove the fields. However, at this juncture, since it does not even appear to be called, I am first focusing on the basic setup that I have.

file: app/code/community/MyCompany/Profile/etc/config.xml

...
    <blocks>
        <profile>
            <class>MyCompany_Profile_Block</class>
        </profile>
        <adminhtml>
            <rewrite>
                <customer_edit_tab_account>MyCompany_Profile_Block_Adminhtml_Customer_Edit_Tab_Account</customer_edit_tab_account>
            </rewrite>
        </adminhtml>
    </blocks>

I'm not getting the die() or any error thrown. I'm assuming that there is some small yet non-trivial item that I'm not setting/calling.

P.S. I do not want to remove the customer attributes from Magento, which is why I am trying to suppress/remove them from the adminhtml tab on which they appear.

P.P.S. Caching is completely disabled, so it is not a config caching issue.

1

There are 1 best solutions below

0
On

I was just looking through some Magento stuff and I came across this one.

Just in case if someone got stuck with similar approach this could help.

First create the modules xml file; File: /app/etc/modules/MyCompany_Profile.xml

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <modules>
        <MyCompany_Profile>
            <active>true</active>
            <codePool>community</codePool>
            <version>1.0.0</version>
        </MyCompany_Profile>
    </modules>
</config>

Important: since codePool is community, we'll put our plugin accordingly under /app/code/community/ if codePool would be local than we would put our plugin under /app/code/local/

Now let's create our config.xml File: /app/code/community/MyCompany/Profile/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <modules>
        <MyCompany_Profile>
            <version>1.0.0</version>
        </MyCompany_Profile>
    </modules>

    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <customer_edit_tab_account>
                        MyCompany_Profile_Block_Customer_Edit_Tab_Account
                    </customer_edit_tab_account>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

Now we can create our class;

File: /app/code/community/MyCompany/Profile/Block/Customer/Edit/Tab/Account.php

class MyCompany_Profile_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Block_Customer_Edit_Tab_Account
{

    /**
     * Form initiation modification
     */
    public function initForm()
    {
        die('hello world!');
    }
}

Now, if you are using cache, you need to clear it as Magento won't see newly generated XML files thus won't be able to read & recognize our module and our module's config.xml

Once it is done, go ahead to visit a profile, you'll see Hello World printed on the screen.