使用选择框扩展类别属性集(多选)

时间:2017-09-13 09:31:38

标签: php magento magento-1.9

我正在尝试完成一个带有多个选项的选择框 - 在类别的后端选择。

到目前为止,创建选择框的脚本正在运行,但只能使用单选。

$installer = $this;
$installer->startSetup();

$attribute  = array(
        'group'                     => 'Examplegroup',
        'input'                     => 'select', // also tried multiselect
        'type'                      => 'varchar',
        'label'                     => 'Examplelabel',
        'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'                   => 1,
        'required'                  => 0,
        'visible_on_front'          => 0,
        'is_html_allowed_on_front'  => 0,
        'is_configurable'           => 0,
        'searchable'                => 0,
        'filterable'                => 1,
        'comparable'                => 0,
        'unique'                    => false,
        'user_defined'              => true,
        'default'                   => '',
        'is_user_defined'           => false,
        'used_in_product_listing'   => true,
        'option'                    => array('values' => array('option1', 'option2', 'option3', 'option4'))
);
$installer->addAttribute('catalog_category', 'attribute_name', $attribute);


$installer->endSetup();

我如何实现这个

multiselect

我认为它应该与输入类型的multiselect一起使用,但它在升级后保留了一个选择选项。

1 个答案:

答案 0 :(得分:1)

对于多选选项,请将input设置为multiselect并添加backend模型eav/entity_attribute_backend_array

$installer = $this;
$installer->startSetup();

$attribute  = array(
        'group'                     => 'Examplegroup',
        'input'                     => 'multiselect',
        'type'                      => 'varchar',
        'label'                     => 'Examplelabel',
        'backend'                   => 'eav/entity_attribute_backend_array',
        'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'                   => 1,
        'required'                  => 0,
        'visible_on_front'          => 0,
        'is_html_allowed_on_front'  => 0,
        'is_configurable'           => 0,
        'searchable'                => 0,
        'filterable'                => 1,
        'comparable'                => 0,
        'unique'                    => false,
        'user_defined'              => true,
        'default'                   => '',
        'is_user_defined'           => false,
        'used_in_product_listing'   => true,
        'option'                    => array('values' => array('option1', 'option2', 'option3', 'option4'))
);
$installer->addAttribute('catalog_category', 'attribute_name', $attribute);


$installer->endSetup();

运行以下升级脚本以更新现有属性

$installer->startSetup();

$installer->updateAttribute('catalog_category', 'attribute_name', 'frontend_input', 'multiselect');
$installer->updateAttribute('catalog_category', 'attribute_name', 'backend_model', 'eav/entity_attribute_backend_array');

$installer->endSetup();

检查beforeSave类的Mage_Eav_Model_Entity_Attribute_Backend_Array函数,以了解后端模型。

希望它有所帮助!

相关问题