Magento 将下拉列表属性添加到类别-设置源
我为产品添加了“品牌”属性(下拉列表)。 我正在尝试使用“品牌”属性中的值向类别添加新属性(下拉列表)。 我应该如何为该类别属性设置正确的源。 请参阅mysql安装文件中的我的代码:Magento 将下拉列表属性添加到类别-设置源,magento,magento-1.7,Magento,Magento 1.7,我为产品添加了“品牌”属性(下拉列表)。 我正在尝试使用“品牌”属性中的值向类别添加新属性(下拉列表)。 我应该如何为该类别属性设置正确的源。 请参阅mysql安装文件中的我的代码: $this->startSetup(); $this->addAttribute('catalog_category', 'brand', array( 'group' => 'General', 'type'
$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\u MyModule\u Model\u SelectAttributes扩展Mage\u Eav\u Model\u Entity\u Attribute\u Source\u 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""
我猜您的源模型位于名为
Selectattributes.php
的文件中。如果使用区分大小写的文件系统,则需要执行以下两项操作之一:
- 将类定义文件重命名为
或Selectattributes.php
- 将您的品牌的
值更改为source\u model
mymodule/selectAttributes
MyPackage_MyModule_Model_Selectattributes
MyPackage/MyModule/Model/Selectattributes.php
请注意文件名的问题。请注意,这应该在不区分大小写的文件系统中工作。我猜您的源模型位于名为
Selectattributes.php的文件中。如果使用区分大小写的文件系统,则需要执行以下两项操作之一:
- 将类定义文件重命名为
Selectattributes.php
或
- 将您的品牌的
source\u model
值更改为mymodule/selectAttributes
当Magento试图为属性实例化源模型时,正在计算的类名(以及自动加载包含路径)的工作方式如下:
MyPackage_MyModule_Model_Selectattributes
MyPackage/MyModule/Model/Selectattributes.php
请注意文件名的问题。请注意,这应该在一个不区分大小写的文件系统中工作。你是对的:)我更改了mymodule/SelectAttributes的source_模型的值,现在工作正常。非常感谢:)你说得对:)我更改了mymodule/SelectAttributes的源代码模型的值,现在它运行良好。非常感谢:)