2017-09-13 58 views
0

我试图完成一个选择框与多个选项 - 在类别的后端选择。使用选择框(多选)扩展类别属性集

创建选择框的脚本到目前为止仍在工作,但仅限于单一选择。

$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

我认为它应该与输入型多选的工作,但它一直在升级后单选择选项。

回答

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

检查Mage_Eav_Model_Entity_Attribute_Backend_Array类的beforeSave函数来获取后端模式的更多想法。

希望它有帮助!

+0

这正是我想要的。谢谢朋友! – Slatyoo