I am trying to update attribute option label with attribute optionid.
Used below code.
class Attribute
{
protected $eavAttributeFactory;
public function __construct(
\Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory
) {
$this->eavAttributeFactory = $eavAttributeFactory;
}
public function attributeUpdate() {
$attribute_code = 'color';
$optionid = 12345;
$option_label = 'red';
$attr = $this->productAttributeRepository->get($attribute_code );
$options = $attr->getOptions();
$values = 0;
foreach ($options as $option) {
if ($option->getValue() == $magento_id) {
$option->setLabel($option_label);
//$option->setStoreLabels([$option_label]);
$attr->setOptions([$option]);
$this->productAttributeRepository->save($attr);
break;
}
$values++;
}
}
Option id 12345 is Green now. I need to Update to Red. What code i need to use to update label of option. Please anyone help on this. Right now it is updating only in admin end. not for all stores, like in Default store view Label in empty. Thanks