0

Can you Please guide how can I add new tab in admin side customer module with some custom attribute?

I create below files, But still not get anything, No tab added, Please check and correct me if anything goes wrong.

1) app/code/local/Customtab/CustomerAccount/etc/config.xml

<?xml version="1.0"?>
<config>
   <modules>
       <Customtab_CustomerAccount>
           <version>0.1.0</version>
       </Customtab_CustomerAccount>
   </modules>
 <adminhtml>
    <layout>
           <updates>
               <customeraccount>
                  <file>customeraccount.xml</file>
               </customeraccount>
           </updates>
       </layout>
   </adminhtml>  
   <global>
       <blocks>
           <customeraccount>
               <class>Customtab_CustomerAccount_Block</class>
           </customeraccount>
       </blocks>
 </global>
</config>

2.) app/etc/modules/Customtab_Customeraccount.xml

<?xml version="1.0"?> 
  <config>
   <module>
  <Customtab_CustomerAccount>
      <active>true</active>
      <codePool>local</codePool>
  </Customtab_CustomerAccount>
  </module>
  </config>

3.) app/code/local/Customtab/CustomerAccount/Block/Adminhtml/Customer/Edit/Tab/Action.php

<?php 

    /**
     * Adminhtml customer insurance tab
     *
     */
    class Customtab_CustomerAccount_Block_Adminhtml_Customer_Edit_Tab_Action
     extends Mage_Adminhtml_Block_Template
        implements Mage_Adminhtml_Block_Widget_Tab_Interface
    {

        public function __construct()
        {
            $this->setTemplate('customeraccount/action.phtml');

        }

        public function getCustomtabInfo(){

            $customer = Mage::registry('current_customer');
            $customtab='Custom tab insurance settings is here';
            return $customtab;
            }

        /**
         * Return Tab label
         *
         * @return string
         */
        public function getTabLabel()
        {
            return $this->__('Insurance Settings');
        }

        /**
         * Return Tab title
         *
         * @return string
         */
        public function getTabTitle()
        {
            return $this->__('Insurance Tab');
        }

        /**
         * Can show tab in tabs
         *
         * @return boolean
         */
        public function canShowTab()
        {
            $customer = Mage::registry('current_customer');
            return (bool)$customer->getId();
        }

        /**
         * Tab is hidden
         *
         * @return boolean
         */
        public function isHidden()
        {
            return false;
        }

         /**
         * Defines after which tab, this tab should be rendered
         *
         * @return string
         */
        public function getAfter()
        {
            return 'tags';
        }

    }
    ?>

4.) app/design/adminhtml/default/default/template/customeraccount/action.phtml

<div>
New Custom Tab
</div>

5.) app/design/adminhtml/default/default/layout/customeraccount.xml

customer_edit_tab_action customeraccount/adminhtml_customer_edit_tab_action

4
  • have a look at this mydons.com/how-to-add-custom-tabs-to-magento-customer-edit-page – Piyush Nov 28 '16 at 7:04
  • @Piyush, Please check my question I Edit it, Let me know if I am doing anything wrong. – Yogita Nov 28 '16 at 7:52
  • path app/etc/module/Customtab_Customeraccount.xml should be app/etc/modules/Customtab_Customeraccount.xml – Piyush Nov 28 '16 at 9:03
  • @Piyush, Thanks for your link, it is really helpful. – Yogita Nov 28 '16 at 9:37
3

In your custom module add below code in layout xml file

<adminhtml_customer_edit>
    <reference name="customer_edit_tabs">
        <action method="addTab"><name>customtab_name</name><block>modulename/adminhtml_customer_tab</block></action>
    </reference>
</adminhtml_customer_edit>

Create block file in your custom module

<?php
class Namespace_Modulename_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('template path here');
    }
   /**
     * 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;
    }
}

EDIT

add below code in file Customtab_Customeraccount.xml at app/etc/modules/Customtab_Customeraccount.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Customtab_CustomerAccount>
            <active>true</active>
            <codePool>local</codePool>
            <depends />
        </Customtab_CustomerAccount>
    </modules>
</config>

You need to change your Action.php below code

public function canShowTab()
        {
            $customer = Mage::registry('current_customer');
            return (bool)$customer->getId();
        }

to:

public function canShowTab()
        {

            return true;
        }
7
  • Please check my question I Edit it, Let me know if I am doing anything wrong. – Yogita Nov 28 '16 at 7:51
  • @yogita your code is correct any error there? – Prashant Valanda Nov 28 '16 at 8:33
  • No Error, And I don't see any New tab in my customer module admin side. – Yogita Nov 28 '16 at 8:54
  • The Path is right but Miss to mention : <config> and <module> in Customtab_Customeraccount.xml <br/> Now Tab appears but only when I edit any customer not in add new customer, I want the tab in both. – Yogita Nov 28 '16 at 9:17
  • @Yogita updated answer check it – Prashant Valanda Nov 28 '16 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.