Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Adding New Tab to Customer Edit in admin
 
mikrophon
Jr. Member
 
Total Posts:  2
Joined:  2010-02-12
 

I’ve tried a few different ways to do this, unfortunately I couldn’t get any page to display when the tab was clicked.

Now I have a new problem, I can’t get the additional tab to display at all. I’ve been knocking my head against the desk all day trying to figure this out. I need some help please, code below.

app/code/local/Avi/Customercc/etc/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Avi_Customercc>
            <
version>0.1.0</version>
        </
Avi_Customercc>
    </
modules>
    <global>
        <
blocks>
            <
customercc>
                <class>
Avi_Customercc_Block</class>
            </
customercc>
        </
blocks>
        <
models>
            <
customercc>
                <class>
Avi_Customercc_Model</class>
            </
customercc>
        </
models>
    </global>
    <
adminhtml>
        <
layout>
            <
updates>
                <
customercc>
                    <
file>avi_customercc.xml</file>
                </
customercc>
            </
updates>
        </
layout>
    </
adminhtml>
</
config>

app/design/adminhtml/default/default/layout/avi_customercc.xml

<?xml version="1.0"?>
<layout>
    <
adminhtml_customer_edit>
        <
reference name="customer_edit_tabs">
            <
action method="addTab">
                <
name>my_custom_tab</name>
                <
block>customercc/adminhtml_customer_tab</block>
            </
action>
        </
reference>
    </
adminhtml_customer_edit>
</
layout>

app/code/local/Avi/Customercc/Block/Adminhtml/Customer/Tab.php

<?php
class Avi_Customercc_Block_Adminhtml_Customer_Tab
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface {
   
/**
     * Set the template for the block
     *
     */
    
public function _construct()
    
{
        parent
::_construct();
       
$this->setTemplate('customercc/customer/tab.phtml');
    
}
   
/**
     * Retrieve the label used for the tab relating to this block
     *
     * @return string
     */
    
public function getTabLabel()
    
{
        
return $this->__('My Custom Tab');
    
}
    
/**
     * Retrieve the title used by this tab
     *
     * @return string
     */
    
public function getTabTitle()
    
{
        
return $this->__('Click here to view your custom tab content');
    
}
   
/**
     * Determines whether to display the tab
     * Add logic here to decide whether you want the tab to display
     *
     * @return bool
     */
    
public function canShowTab()
    
{
        
return true;
    
}
    
/**
     * Stops the tab being hidden
     *
     * @return bool
     */
    
public function isHidden()
    
{
        
return false;
    
}
}

app/design/adminhtml/default/default/template/customercc/customer/tab.phtml

<?php
/**
 * Custom tab template
 */
?>
<div class="input-field">
 <
label for="custom_field">Custom Field</label>
 <
input type="text" class="input-text" name="custom_field" id="custom_field" />
</
div>

Any help is greatly appreciated

 
Magento Community Magento Community
Magento Community
Magento Community
 
SimonLindner
Member
 
Avatar
Total Posts:  31
Joined:  2011-09-08
Bremen
 

Same problem here.

As far as I can tell, your approach should be correct - and mine is too, as my code looks nearly the same.

Did you have any success with this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
SimonLindner
Member
 
Avatar
Total Posts:  31
Joined:  2011-09-08
Bremen
 

Ok, I got it

I had my layout-update im adminhtml.xml and not in config.xml of my module; worked fine for another update, but not for this one

I guess you should check first if you can use the <addTab> method in a core-layout file, i.e. sales.xml; if this works, the mistake is somewhere in your xml-files and not in the php

 
Magento Community Magento Community
Magento Community
Magento Community
 
SimonLindner
Member
 
Avatar
Total Posts:  31
Joined:  2011-09-08
Bremen
 

Hey Monti,

thanks for this solution.

An experienced developer as you should know to never touch core files in any way; Magento is built as modular as possible for this reason.

Changing core-files is always a fast hack, but it removes your system\’s update-ability.

You should at least mention that people using your solution should copy all used files from app/code/core/Mage/… to app/code/local/Mage...; still not the \"real\" Magento-way, but update-safe

 
Magento Community Magento Community
Magento Community
Magento Community
 
mathanganesh
Jr. Member
 
Total Posts:  2
Joined:  2012-02-14
 
Monty22 - 28 February 2013 11:25 PM

Hi!!

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.

If you need any kind of help you can contact us as we are one of best Magento extensions developer.

Thanks

Monty
iLoveMage

Get 25% discount all our Magento Extensions.

I have tried your way it seems not working for me. I’m getting this error.

Fatal error: Call to a member function setCustomerId() on a non-object in /home/chirka/public_html/app/code/core/Mage/Adminhtml/controllers/CustomerController.php on line 568

Image Attachments
Mathan raj - Manage Customers - Customers - Magento Admin 2013-09-12 19-57-44.png
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top