Tzu ng
Tzu ng

Reputation: 9244

Magento - Assign option to multiselect attribute programmatically

I have a custom attribute which is multi select type and I want to assign the value for it programatically but it doesn't work like "text field" attribute.

At the moment, I use the product.update in Magento's SOAP API to update the additional attribute.

I've tried and searched and tried but unluckily they didn't seem to work. I think this should work normally by default and we need some hack?

Is there any official document from magento about these kind of work ?

Upvotes: 2

Views: 3879

Answers (1)

Swapna
Swapna

Reputation: 401

It is possible to write a setup script to add value to the multiselect attribute. Considering your attribute is color and you are trying to add value 'Red','Green','Blue' to the attribute, then you add like this

$oInstaller = new Mage_Eav_Model_Entity_Setup('core_setup');
$iAttribId = $oInstaller->getAttributeId('catalog_product', 'color');
$oInstaller->addAttributeOption(array(
        'attribute_id' => $iAttribId, 
        'value' => array(
            array(
                0 => 'Red',
                1 => 'Blue',
                2=> 'Green'
            )
        ),
    ));

Hope this works.

Upvotes: 4

Related Questions