Set Multiselect Attribute Using Attribute Code – Magento 1.9 Guide

magento-1.9multiselect-attributeproduct-attribute

I am trying to create products programmatically. In the task, I need to set the multiselect attribute options. I tried like below, but it is not working.

$optionIds[] = $optionId; //$optionIds = array(41,42,43)
$product->setData($attributeCode, $optionIds);

But it is not working. I don't know what I am doing wrong. Can anyone help on this?

Best Answer

Multiselect values are saved id db as imploded string, so if you created your attribute correctly, imploding array should solve the problem.