1

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?

Rakesh Jesadiya
42.5k19 gold badges135 silver badges186 bronze badges
asked Apr 13, 2016 at 8:24

2 Answers 2

1

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

answered Apr 13, 2016 at 8:43
2
  • May I know the table name? Commented Apr 13, 2016 at 8:53
  • catalog_product_entity_varchar Commented Apr 13, 2016 at 8:55
3

The values from multiselect attributes are saved concatenated by comma 1,4,6 so you need to replace your code from

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

To

$optionIds = implode(',',$optionId); //$optionIds = array(41,42,43)
$product->setData($attributeCode, $optionIds);
answered Apr 13, 2016 at 9:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.