Search code examples
akeneo

Akeneo: Edit an attribute option


I want to change an attribute option label and store it with Akeneo 1.4.9, but I don't know which handlers/factories I should use.

I used MyAttributeOptionValueInterface->setLabel('new Label') to change the label. How can I save the result in the database?

My idea:

  1. Remove the old option from the attribute (AttributeInterface->removeOption(optionWithOldLabel))
  2. Add it again (AttributeInterface->addOption(optionWithNewLabel))
  3. Store the attribute in the database (how?).

Is this the correct way? Any hints are welcome.


Solution

  • You can use object savers of the PIM: http://docs.akeneo.com/latest/cookbook/catalog/common/save.html?highlight=saver

    And save your options like that:

    $attributeOption->setLabel('My nice label');
    $attributeOptionSaver = $this->getContainer()->get('pim_catalog.saver.attribute_option');
    $attributeOptionSaver->save($attributeOption);
    

    And you are good to go !