Question

I am working on a magento extension that automatically creates products from an import file. Everything is going great, except for one small issue i can't seem to figure out.

I have created a few multiselect attributes for all products, but my setData function does not process multiple values for those attributes. Assigning 1 value is no problem though.

my current code (simplified):

$magentoProductModel->setData('multiselect_attribute', array(1, 3, etc));
$magentoProductModel->save();

This doesn't do anything. When i assign only 1 id like this:

$magentoProductModel->setData('multiselect_attribute', 1);
$magentoProductModel->save();

It will assign the correct value.

But i really want to assign more than 1 value. It isn't a multiselect attribute for nothing.

Methods i have tried so far:

$magentoProductModel->setData('multiselect_attribute', array(1, 3, etc));
$magentoProductModel->save();

$magentoProductModel->setData('multiselect_attribute', [1, 3, etc]);
$magentoProductModel->save();

$multiselect_ids = array(1, 3, etc); 
foreach($multiselect_ids as $multiselect_id) {
  $magentoProductModel->setMultiselectAttribute($multiselect_id);
}
$magentoProductModel->save();

None of the above methods work. Can't seem to figure out the right way to fix this. Does anyone know how to get this to work?

Was it helpful?

Solution

try with $magentoProductModel->setData('multiselect_attribute', '1,2,3');

I mean, concatenate the values using comma.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top