1

I am working in a custom module, using which I want to add some custom attributes in my custom tab. By following through lot of tutorials I made custom attribute and successfully output it in one of the default tab in customer section in admin. Now I want to display it in my custom tab..

However I need some clarification on custom attributes for doing this. following is my customer attribute details that I forcefully printed in admin side...

Array
(
[attribute_id] => 961
[entity_type_id] => 1
[attribute_code] => nick_name
[attribute_model] => 
[backend_model] => 
[backend_type] => varchar
[backend_table] => 
[frontend_model] => 
[frontend_input] => text
[frontend_label] => Nick Name
[frontend_class] => 
[source_model] => 
[is_required] => 0
[is_user_defined] => 1
[default_value] => 
[is_unique] => 0
[note] => 
[is_visible] => 1
[input_filter] => 
[multiline_count] => 0
[validate_rules] => 
[is_system] => 1
[sort_order] => 100
[data_model] => 
[entity_type] => Mage_Eav_Model_Entity_Type Object
    (
        [_attributes:protected] => 
        [_attributesBySet:protected] => Array
            (
            )

        [_sets:protected] => 
        [_eventPrefix:protected] => core_abstract
        [_eventObject:protected] => object
        [_resourceName:protected] => eav/entity_type
        [_resource:protected] => 
        [_resourceCollectionName:protected] => eav/entity_type_collection
        [_cacheTag:protected] => 
        [_dataSaveAllowed:protected] => 1
        [_isObjectNew:protected] => 
        [_data:protected] => Array
            (
                [entity_type_id] => 1
                [entity_type_code] => customer
                [entity_model] => customer/customer
                [attribute_model] => customer/attribute
                [entity_table] => customer/entity
                [value_table_prefix] => 
                [entity_id_field] => 
                [is_data_sharing] => 1
                [data_sharing_key] => default
                [default_attribute_set_id] => 1
                [increment_model] => eav/entity_increment_numeric
                [increment_per_store] => 0
                [increment_pad_length] => 8
                [increment_pad_char] => 0
                [additional_attribute_table] => customer/eav_attribute
                [entity_attribute_collection] => customer/attribute_collection
            )

        [_hasDataChanges:protected] => 1
        [_origData:protected] => 
        [_idFieldName:protected] => entity_type_id
        [_isDeleted:protected] => 
        [_oldFieldsMap:protected] => Array
            (
            )

        [_syncFieldsMap:protected] => Array
            (
            )

    )

 )

My questions are

1) How can I display this custom attribute in my custom tab? For example:

if (version_compare(Mage::getVersion(), '1.4.2', '>='))
{
Mage::getSingleton('eav/config')
    ->getAttribute('customer', 'nick_name')
    ->setData('used_in_forms', array('adminhtml_customer','mysite_custmernewtab',))
    ->save();
}

where mysite_customernewtab is my module. Whether this method automatically print input field in my custom module? or is it necessary that I want to load this field manually through custom phtml file?

2)I have seen frontend_label,frontend_input datas in the output. Whether it can be used to print input field in admin side? or is there backend_input, backend_label exist similar to this ?

3)what is this source and backend data? I have seen these items when add an attribute through set up file..

Please help me to understand this... It will help others also.. Thanks in advance

1

Firstly the section for used_in_forms is really only for the form and not the tab, so you should remove the second section.

 ->setData('used_in_forms', array('adminhtml_customer'))

New Admin Tab - Via Layout Xml

You can add a new tab to the customer form with the following layout xml. You can add a new module with an adminhtml layout update that contains the following.

<layout version="0.1.0">
  <adminhtml_customer_edit>
     <reference name="customer_edit_tabs">
        <action method="addTab">
          <name>customer_edit_tab_new</name>
          <block>your_module/adminhtml_customer_edit_tab_new</block>
        </action>
     </reference>
  </adminhtml_customer_edit>
</layout>

This will add a new tab of type Your_Module_Block_Adminhtml_Customer_Edit_Tab_New. Then you can simply make your tab in the same format as Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter and this will add the new tab.

New Admin Tab - Via Php

If you want to add a new tab to the customer edit form in the admin then you will need to firstly rewrite Mage_Adminhtml_Block_Customer_Edit_Tabs so that you can add a new section to the function _beforeToHtml. Here you can add something like.

$this->addTab('new_tab_name', array(
    'label'     => Mage::helper('your_module')->__('New Tab Name'),
    'content'   => $this->getLayout()->createBlock('your_module/adminhtml_customer_edit_tab_new')->initForm()->toHtml(),
    'active'    => Mage::registry('current_customer')->getId() ? false : true
));

Again this will add a new tab of type Your_Module_Block_Adminhtml_Customer_Edit_Tab_New. Then you can simply make your tab in the same format as Mage_Adminhtml_Block_Customer_Edit_Tab_Newsletter and this will add the new tab.

In my opinion the layout xml is the cleanest solution as it does not involve rewriting any code, but I thought I would mention both as it is good to see all options. There is also a good tutorial on this that can he found here

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.