Magento 如何使用EAV AddAttribute设置默认值
我想在magento中为我的产品设置一个新属性集。此属性应为某些选项中的选择类型Magento 如何使用EAV AddAttribute设置默认值,magento,select,attributes,option,entity-attribute-value,Magento,Select,Attributes,Option,Entity Attribute Value,我想在magento中为我的产品设置一个新属性集。此属性应为某些选项中的选择类型 $installer->addAttribute('catalog_product', 'reserve', array( 'backend_label' => 'Attribute Reserve', 'type' => 'varchar', 'input' => 'select', #'backen
$installer->addAttribute('catalog_product', 'reserve', array(
'backend_label' => 'Attribute Reserve',
'type' => 'varchar',
'input' => 'select',
#'backend' => 'eav/entity_attribute_source_boolean',
'frontend' => '',
'source' => '',
#'default' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'option' => array(
'value' => array(
'optionone' => array( 'O' ),
'optiontwo' => array( 'P' ),
'optionthree' => array( 'Kein Angabe' ),
)
),
));
如何将选项树设置为默认值?导航到目录>管理属性以创建新属性,管理属性树以创建新属性集
请检查屏幕截图请使用此脚本:-
$installer->addAttribute('catalog_product', 'reserve', array(
'backend_label' => 'Attribute Reserve',
'type' => 'varchar',
'input' => 'select',
#'backend' => 'eav/entity_attribute_source_boolean',
'frontend' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'visible_in_advanced_search' => false,
'option' => array(
'value' => array(
'optionone' => array( 'O' ),
'optiontwo' => array( 'P' ),
'optionthree' => array( 'Kein Angabe' ),
)
),
/**
* This will set the default values,
* as "array" data type is being used to set proper default value
*/
'default' => array(
'optionthree'
),
));
希望有帮助。也有同样的问题。我的解决方案:
$installer->addAttribute('catalog_product', 'reserve', array(
'backend_label' => 'Attribute Reserve',
'type' => 'int',
'input' => 'select',
#'backend' => 'eav/entity_attribute_source_boolean',
'frontend' => '',
'source' => 'eav/entity_attribute_source_table',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'visible_in_advanced_search' => false,
'option' => array(
'value' => array(
'optionone' => array( 'O' ),
'optiontwo' => array( 'P' ),
'optionthree' => array( 'Kein Angabe' ),
)
),
));
注意不同的类型(int
而不是varchar
)和源(eav/entity\u attribute\u source\u table
)。这是Magento表示典型选择属性的方式。现在可以按如下方式设置默认值:
$model = Mage::getModel('eav/entity_attribute')
->load($installer->getAttributeId('catalog_product', 'reserve'));
$model
->setDefaultValue($model->getSource()->getOptionId('Keine Angabe'))
->save();
谢谢您的回答,但我想使用installscript获取属性。@koenig-您是否已从此数据库表“
core\u resource
”中删除了您的模块唯一组码?如果数据库中存在唯一的组码,则不会调用您的安装脚本。