Magento Themes and Magento Extensions

Magento – Add a new tab on customer edit page


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

In Magento: 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

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

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.

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

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

01 class Mage_Adminhtml_Block_Customer_Edit_Tab_Survey extends Mage_Adminhtml_Block_Widget_Form
02 {
04 public function __construct()
05 {
06 parent::__construct();
07 $this->setTemplate('customer/tab/survey.phtml');
08 }
10 }

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 Reply

You must be logged in to post a comment.