Yes it's possible programmatically thanks to the method Mage_Eav_Model_Entity_Setup::updateAttribute($entityTypeId, $id, $field, $value=null, $sortOrder=null)
It's not possible with the Attribute Management in Magento Backend because it has consequence with the existing data. In your case, changing from select to multiselect should be ok but do a database backup and test if your product are still correctly displayed.
Programmatically, the best way is to do it from an update setup script. I don't know your module but here are some information to do it.
An update setup script is launched when you provide a new number version to your module and you provide a setup script with the old and new version number as a filename.
1) Here is the header of a config.xml module, change it to provide a higher version. For example, the new version is
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Mycompany_Mymodule>
<version>1.0.1</version><!-- the old one was 1.0.0 -->
</Mycompany_Mymodule>
</modules>
...
</config>
2) you need to have in the config.xml file, between the tags <global>...</global>
the following code, please adapt to your situation:
<resources>
<mymodule_setup><!-- name that you will give to the folder into the sql folder -->
<setup>
<module>Mycompany_Mymodule</module>
<class>Mage_Eav_Model_Entity_Setup</class><!-- You can have a setup class which extends this class -->
</setup>
<connection>
<use>default_setup</use>
</connection>
</mymodule_setup>
</resources>
3) Then you need to create a setup script in your module folder with the old and new version number app/code/local/mycompany/mymodule/sql/mymodule_setup/mysql4-upgrade-1.0.0-1.0.1.php
(mysql4-upgrade-old.version.number-new.version.number.php)
4) And in this new script set a code like this, please adapt to your situation:
<?php
$installer = $this;
/*@var $installer Mage_Eav_Model_Entity_Setup */
$entityTypeId = $installer->getEntityTypeId('catalog_product');
$idAttributeOldSelect = $this->getAttribute($entityTypeId, 'myold_attribute', 'attribute_id');
$installer->updateAttribute($entityTypeId, $idAttributeOldSelect, array(
'frontend_input' => 'multiselect'
));
5) Refresh your Magento page and eventually flush your cache
'frontend_input'
in theupdateAttribute()
call, not'input'
. (Tested on Magento 1.9.0.1) – Headlight