Reputation: 139
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.
Upvotes: 1
Views: 1474
Reputation: 51
This answer is probably 9+ years too late, but this is what we came up with when figuring out how to do this. Also note that this was tested and working on OpenMage 20.x branch, but hopefully the code in question is still pretty much the same to Magento 1.9.
Mage_Adminhtml_Block_Customer_Edit_Tab_Account
(initForm
) is responsible for rendering the customer attributes seen in the My Account area. If you look around line 41 at this code:
/** @var Mage_Customer_Model_Form $customerForm */
$customerForm = Mage::getModel('customer/form');
$customerForm->setEntity($customer)
->setFormCode('adminhtml_customer')
->initDefaultValues();
This code is how Magento knows which attributes to show in the My Account tab. The Mage_Customer_Model_Form
is loading all attributes associated with form_code
adminhtml_customer
(you can see these in the customer_form_attribute
table). If you want certain attributes to not show you should either remove them from the customer_form_attribute
table completely, or change their form_code
to something other than adminhtml_customer
. Note however that this will prevent these attributes from being saved through the admin customer form.
Upvotes: 0
Reputation: 443
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.
Upvotes: 0