I am creating a product programaticlly, and sometimes I need to add a new option to some product attribute. For adding the new option my code is:

$option = array();
$option['attribute_id'] = $attribute->getId();
$option['value']['$attributeValue'][0] = $attributeValue;

$eavSetup = $eavSetupFactory->create();

If I do a


to get the new optionId, nothing is returning, and then I can not add this attribute value to my new product.

If I go to backend the new attribute is being created.

Do anyone knows how can I get the Id from my new created attribute option?

  • Which is your $attribute class? – Khoa TruongDinh Jan 11 '17 at 15:05
  • the class is \Magento\Eav\Api\AttributeRepositoryInterface – mvistas Jan 11 '17 at 15:31

Your Answer

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

Browse other questions tagged or ask your own question.