I am trying to add a multiselect by my install script. This is my code:
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();
$options = array();
foreach(Mage::getModel('adminhtml/system_config_source_country')->toOptionArray() as $option) {
$options["value"][$option["value"]] = array($option["label"]);
}
$installer->addAttribute('catalog_product', 'allowed_countries', array(
'group' => 'General',
'type' => 'varchar',
'input' => 'multiselect',
'label' => 'Restrict shipping to',
'backend' => 'eav/entity_attribute_backend_array',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'configurable' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'option' => $options
));
$installer->endSetup();
The problem is that the values of the options are not the values of the array $options.
For example: Magento changes "US" => "United States" to "8396" => "United States"
Any ideas?
Here is the solution:
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
$installer->startSetup();
$installer->addAttribute('catalog_product', 'allowed_countries', array(
'group' => 'General',
'type' => 'varchar',
'input' => 'multiselect',
'label' => 'Restrict shipping to',
'backend' => 'eav/entity_attribute_backend_array',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'configurable' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'source' => 'customer/entity_address_attribute_source_country'
));
$installer->endSetup();