Reputation: 1712
I'm trying to create a tab called Additonal in admin customer edit and place my custom employee attribute in it. Is this possible in via my modules sql setup? This question is relevant only to Magento >= 1.5.1.
$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer', 'employee', array(
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Employee Status',
'input' => 'select',
'class' => '',
'source' => 'boilerplate/customer_attribute_status',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false
));
$attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'employee');
$attribute->addData(array('sort_order'=>50));
$attribute->setData('used_in_forms', array('adminhtml_customer'));
$attribute->save();
Below is not working. Here I'm trying to create a tab in backend admin customer edit and place my emploee attribute in it.
$entityTypeId = $installer->getEntityTypeId('customer');
$attributeId = $installer->getAttributeId('customer', 'employee');
$attributeSets = $installer->_conn->fetchAll('select * from '.$this->getTable('eav/attribute_set').' where entity_type_id=?', $entityTypeId);
foreach ($attributeSets as $attributeSet) {
$setId = $attributeSet['attribute_set_id'];
$installer->addAttributeGroup($entityTypeId, $setId, 'Additional');
$groupId = $installer->getAttributeGroupId($entityTypeId, $setId, 'Additional');
$installer->addAttributeToGroup($entityTypeId, $setId, $groupId, $attributeId);
}
$installer->endSetup();
Upvotes: 0
Views: 4820
Reputation: 8587
Here is the code to add a tab in admin's customer edit view:
At your module's admin's layout's .xml file, put:
<adminhtml_customer_edit>
<reference name="customer_edit_tabs">
<action method="addTab"><name>tabs_name</name><block>ModuleAlias/path_to_block_file</block></action>
</reference>
</adminhtml_customer_edit>
your block file should extends Mage_Adminhtml_Block_Template
and implements Mage_Adminhtml_Block_Widget_Tab_Interface
(meaning that you'll have to implement some methods), and in the construct you can set the template file, ie:
class Namespace_Module_Block_Adminhtml_Customer_Edit_Tab_History
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function __construct()
{
parent::__construct();
$this->setTemplate('path/to/file.phtml');
}
//down here are the mandatory methods you have to include
public function getTabLabel()
{
return Mage::helper('points')->__('Tab label');
}
public function getTabTitle()
{
return Mage::helper('points')->__('Tab title');
}
public function canShowTab()
{
if (Mage::registry('current_customer')->getId()) {
return true;
}
return false;
}
public function isHidden()
{
if (Mage::registry('current_customer')->getId()) {
return false;
}
return true;
}
}
Upvotes: 2
Reputation: 139
You also can add AJAX tab instead of load all data with page
for example
<layout>
<adminhtml_catalog_product_edit>
<reference name="product_tabs">
<action method="addTab">
<id>mediagallery</id>
<tab>
<label>MediaGallery</label>
<class>ajax</class>
</tab>
</action>
<action method="setTabData">
<id>mediagallery</id>
<key>url</key>
<value>*/catalog_product_mediagallery/index</value>
</action>
</reference>
</adminhtml_catalog_product_edit>
<adminhtml_catalog_product_mediagallery_index>
<block type="mediagallery/adminhtml_catalog_product_edit_tab_gallery" name="root" output="toHtml" template="mediagallery/container.phtml">
</block>
</adminhtml_catalog_product_mediagallery_index>
<adminhtml_catalog_product_mediagallery_image>
<block type="mediagallery/adminhtml_catalog_product_edit_tab_gallery_image" name="root"></block>
</adminhtml_catalog_product_mediagallery_image>
</layout>
adminhtml_catalog_product_mediagallery_index - render content: grid contained and some custom buttons/
adminhtml_catalog_product_mediagallery_image - grid url for grid which was rendered in previous handle
Upvotes: 0