Magento – Multi Select Category Attribute not saving

attributescategoryce-1.9.0.0multiselect-attribute

I'm using Magento Community 1.9.0.0.

I have programmatically created a custom category attribute which is a multi select. The attribute can be seen in my admin category section. When i select any values – whether it's one or more and press save i get a successful saved message but the values never save.

I then also tried an extension which creates category attributes. This had the same issue. When i contacted support they said

Category entity does not support multi selection so this type of attribute will not work with category.

Is this true? Can multi select not work on category attributes on CE-1.9?

Here is the code i was using to create it programmatically:

require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute  = array(
    'type' => 'text',
    'label'=> 'Room Type',
    'input' => 'multiselect',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => true,
    'default' => "",
    'group' => "General Information",
    'option' => array ( 
        'value' => array(
            'kitchen' => array('Kitchen'), 
            'bedroom' => array('Bedroom'), 
            'bathroom' => array('Bathroom'), 
            'loft' => array('Loft'), 
            'basement' => array('Basement'), 
            'lounge' => array('Lounge')
        ) 
    )

);
$installer->addAttribute('catalog_category', 'room_type', $attribute);
$installer->endSetup();

Best Answer

Well first it seems that there is an obvious error with $installer->startSetup(); missing near the start, then you may also need to define the backend used for the attribute in order to save it:

'backend'           => 'eav/entity_attribute_backend_array',

Otherwise instead of:

$installer = new Mage_Sales_Model_Mysql4_Setup;

i would try to use:

$installer = new Mage_Eav_Model_Entity_Setup('default_setup');

My two cents hoping it helps you if still needed. :)

the modified code:

require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Eav_Model_Entity_Setup('default_setup');
$installer->startSetup();

$attribute  = array(
    'type' => 'text',
    'label'=> 'Room Type',
    'input' => 'multiselect',
    'backend' => 'eav/entity_attribute_backend_array',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => true,
    'default' => "",
    'group' => "General Information",
    'option' => array ( 
        'value' => array(
            'kitchen' => array('Kitchen'), 
            'bedroom' => array('Bedroom'), 
            'bathroom' => array('Bathroom'), 
            'loft' => array('Loft'), 
            'basement' => array('Basement'), 
            'lounge' => array('Lounge')
        ) 
    )
);

$installer->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'room_type', $attribute);
$installer->endSetup();
Related Topic