在客户编辑中创建自定义选项卡属性

时间:2011-08-23 19:33:01

标签: magento

我正在尝试在管理员客户编辑中创建名为Additonal的标签,并在其中放置我的自定义员工属性。这可以通过我的模块sql设置吗?此问题仅与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();

以下不起作用。在这里,我正在尝试在后端管理员客户编辑中创建一个选项卡,并将我的员工属性放入其中。

$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();

2 个答案:

答案 0 :(得分:2)

以下是在管理员客户编辑视图中添加标签的代码:

  1. 在您模块的管理员布局的.xml文件中,输入:

    <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>
    
  2. 您的块文件应扩展Mage_Adminhtml_Block_Template并实现Mage_Adminhtml_Block_Widget_Tab_Interface(意味着您必须实现某些方法),并且在构造中您可以设置模板文件,即:< / p>

    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;
        }
    }
    

答案 1 :(得分:0)

您还可以添加AJAX选项卡,而不是使用页面

加载所有数据

例如

<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>
  1. 在处理程序
  2. 上添加标签链接
  3. 设置标签数据以设置来自wehre load conten的正确网址
  4. 在控制器中,您可以像我的示例中那样呈现内容或调用布局
  5. adminhtml_catalog_product_mediagallery_index - 呈现内容:包含网格和一些自定义按钮/

    adminhtml_catalog_product_mediagallery_image - 在之前句柄中呈现的网格网格网址