2017-09-13 119 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