Magento – Add a new tab on customer edit page

*This version touches core files. Please make backup before you get started.

I am going to add ‘Survey’ tab and display text

1. Open /app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php
Inside _beforeToHtml() method, add the following code

	$this->addTab('Survey',array(
		'label'	=>Mage::helper('customer')->__('Survey'),
		'class'	=>	'ajax',
		'url'	=>	$this->getUrl('*/*/survey',array('_current'=>true)),
	));

2. If you refresh your browser, you would see that ‘Survey’ tab has been added. Don’t click it just yet.
If you click the link now, you would confront 404 not found error.

3. Open /app/code/core/Mage/Adminhtml/controllers/CustomerController.php
4. Add the following code.

	public function surveyAction(){
		$this->_initCustomer();
		$this->getResponse()->setBody(
			$this->getLayout()->createBlock('adminhtml/customer_edit_tab_survey','admin.customer.survey')->setCustomerId(Mage::registry('current_customer')->getId())
			->setUseAjax(true)
			->toHtml()
		);
	}

as you see in the code, it loads a block. Let’s create that block

5. Go to /app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/ and create Survey.php
6. Add the following source code to the file

class Mage_Adminhtml_Block_Customer_Edit_Tab_Survey extends Mage_Adminhtml_Block_Widget_Form
{

    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('customer/tab/survey.phtml');
    }

}

7. Now, you need to create a template file. Go to /app/design/adminhtml/default/default/template/customer/tab
then create ‘Survey.phtml’

8. Enter your text there

9. Refresh your browser and click ‘Survey’ tab link.

Leave a comment