Here's how I create a new Product multiselect attribute:
$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',
)
);
I've also tried with "Yes/No" values using
"type" => "boolean"
or
"type" => "select",
'source' => 'eav/entity_attribute_source_boolean'
which are functionally identical.
In all cases, having a default
key with value correctly populates the eav_attribute
table, column default_value
. But having "default" => "1"
for "Yes/No" attribute doesn't do anything as far as the input on the edit page is concerned. "No" is still selected, and I was expecting "Yes", because "1" is mapped to "Yes":
// 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
),
);
The same thing happens for multiselect: no option is selected by default.
I'm out of ideas. Does anyone know what's the purpose of the "default" column/key, if not setting a default value of an attribute? How can one set a value of an attribute to be automatically selected on new/edit product backend page?