以编程方式设置multiselect/select Magento属性的默认值
以下是我如何创建新产品的multiselect属性:以编程方式设置multiselect/select Magento属性的默认值,magento,select,default-value,custom-attributes,multi-select,Magento,Select,Default Value,Custom Attributes,Multi Select,以下是我如何创建新产品的multiselect属性: $eav = new Mage_Catalog_Model_Resource_Setup('core_setup'); $eav->addAttribute( Mage_Catalog_Model_Product::ENTITY, "product_country", array( 'label' => 'Country', '
$eav = new Mage_Catalog_Model_Resource_Setup('core_setup');
$eav->addAttribute(
Mage_Catalog_Model_Product::ENTITY,
"product_country",
array(
'label' => 'Country',
'group' => 'General',
'type' => 'text',
'input' => 'multiselect',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
'user_defined' => true,
'required' => true,
'visible' => true,
'source' => 'ns/some_source', // this source has the "UK" value
'backend' => 'eav/entity_attribute_backend_array',
'default' => 'UK',
)
);
我也尝试过使用“是/否”值
"type" => "boolean"
或
功能相同
在所有情况下,使用带有值的default
键将正确填充eav\u属性
表的default\u值列
。但就编辑页面上的输入而言,为“Yes/No”属性设置“default”=>“1”
并没有任何作用。“否”仍处于选中状态,我希望为“是”,因为“1”映射为“是”:
multiselect也会发生同样的情况:默认情况下未选择任何选项
我没有主意了。如果不设置属性的默认值,是否有人知道“default”列/键的用途?如何在新建/编辑产品后端页面上设置自动选择的属性值?我也遇到了这个问题,在创建自定义{product,customer,address}属性和添加实体时出现了一个问题 在Mage_Catalog_Model_Resource_Setup::_prepareValue中定义了一些“默认”实体集,这会导致此问题 最好的解决方案是在创建属性后加载属性并设置默认值
$model = Mage::getModel('eav/entity_attribute')
->load($installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'product_country'));
$model
->setDefaultValue(Mage::helper('eav')->__('Yes'))
->save();
也有这个问题。。你解决了吗?用多选布尔值是没有意义的。。。整点是一个布尔值,有两个值0/1。
// Mage_Eav_Model_Entity_Attribute_Source_Boolean
$this->_options = array(
array(
'label' => Mage::helper('eav')->__('Yes'),
'value' => 1
),
array(
'label' => Mage::helper('eav')->__('No'),
'value' => 0
),
);
$model = Mage::getModel('eav/entity_attribute')
->load($installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'product_country'));
$model
->setDefaultValue(Mage::helper('eav')->__('Yes'))
->save();