Adding a Custom Tab to Customer Edit Page in Magento CE 1.6
As a senior developer, I understand your frustration when trying to add custom features to an older version of Magento like CE 1.6. While the community provides several tutorials, many are outdated or rely on core file edits.
Let’s walk through a clean way to add a tab to the Customer Information page in Magento CE 1.6 using object observer and layout update XML.
Step 1: Create a Custom Module
First, create a new module called Custom_Custom. In your project root folder, navigate to app/code/local:
cd app/code/local
mkdir Custom
mkdir Custom/Custom
Inside the newly created Custom directory, create:
config.xmletc/modules/Custom_All.xml
Step 2: Define the Module
In config.xml, define your module:
<config>
<modules>
<Custom_Custom>
<active>true</active>
<codepool>local</codepool>
<depends>
<Mage_Core />
<Mage_Adminhtml />
</depends>
</Custom_Custom>
</modules>
</config>
And in etc/modules/Custom_All.xml:
<config>
<modules>
<Custom_Custom>
<active>true</active>
<codepool>local</codepool>
<depends>
<Mage_Core />
<Mage_Adminhtml />
</depends>
</Custom_Custom>
</modules>
</config>
Step 3: Create the Custom Tab
Create a new file app/code/local/Custom/Custom/etc/config.xml:
<config>
<global>
<models>
<custom_custom>
<class>Custom_Custom_Model</class>
<resourceModel>custom_custom_resource</resourceModel>
</custom_custom>
<custom_custom_resource>
<class>Custom_Custom_Model_Resource</class>
<entities>
<customer>
<table>customer_entity</table>
</customer>
</entities>
</custom_custom_resource>
</models>
</global>
</config>
Step 4: Create the Layout Update
In app/design/adminhtml/default/default/layout, create a new file called custom_customer.xml:
<layout version="1.0">
<adminhtml_catalog_product_edit>
<reference name="content">
<block type="custom_custom/adminhtml_customer_edit_tab" before="-" name="customer_custom" />
</reference>
</adminhtml_catalog_product_edit>
</layout>
Step 5: Create the Observer
In app/code/local/Custom/Custom/etc/config.xml, add an observer:
<global>
<events>
<catalog_product_edit_tab>
<observers>
<custom_custom_observer>
<type>singleton</type>
<class>Custom_Custom_Model_Observer</class>
<method>addCustomerTab</method>
</custom_custom_observer>
</observers>
</catalog_product_edit_tab>
</events>
</global>
Step 6: Implement the Observer
Create app/code/local/Custom/Custom/Model/Observer.php:
class Custom_Custom_Model_Observer
{
public function addCustomerTab($observer)
{
$form = $observer->getForm();
if ($block = $form->getChild('customer_tabs')) {
$block->append(
'customer_custom',
array(
'label' => Mage::helper('adminhtml')->__('Custom Tab'),
'title' => Mage::helper('custom_custom')->__('Custom Tab')
)
);
}
}
}
Conclusion
With this approach, you avoid editing core files and can maintain your customization even after updates. The key is to leverage Magento’s event-observer system and layout update XML for adding tabs.
Remember to clear your cache and refresh the backend to see your new tab in action.
For more detailed information on Magento development practices, consider exploring Laravel Company’s comprehensive guides.
Happy coding!