3

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();
4

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();
  • What if, I am creating a attribute with a 3rd party extension? like Attribute Manager For category attribute? then how i would make it save the options? – Lalit838 May 19 '17 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.