我为产品添加了“品牌”属性(下拉列表)。我正在尝试将新属性(下拉列表)添加到具有“品牌”属性值的类别。我应该怎么做才能为这个类别属性设置正确的来源。请在 mysql 安装文件中查看我的一段代码:
$this->startSetup();
$this->addAttribute('catalog_category', 'brand', array(
'group' => 'General',
'type' => 'int'
'backend' => '',
'frontend_input' => '',
'frontend' => '',
'label' => 'brand',
'input' => 'select'
'class' => '',
'source' => 'mymodule/selecattributes',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'frontend_class' => '',
'required' => false,
'user_defined' => true,
'default' => '',
'position' => 100,
));
$this->endSetup();
提前致谢。
编辑 1 我添加了类 MyPackage_MyModule_Model_SelectAttributes 扩展扩展 Mage_Eav_Model_Entity_Attribute_Source_Abstract :
class MyPackage_MyModule_Model_SelectAttributes extends Mage_Eav_Model_Entity_Attribute_Source_Abstract{
public function getAllOptions()
{
$attributeCode = 'brand';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attributeCode); //here, "color" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach ($allOptions as $instance) {
$myArray[$instance['value']] = $instance['label'];
}
return $myArray;
}
}
编辑 2 当我打开类别管理页面时,我收到此错误:
"Source model "mymodule/selectattributes" not found for attribute "brands""