Magento2 Attributes – How to Update Attribute Option Programmatically

attributescustom-attributesmagento2

How to update attribute option (update label for a store) programmatically?

enter image description here

Best Answer

Take a look at \Magento\Eav\Model\ResourceModel\Entity\Attribute::_saveStoreLabels(AbstractModel $object). We can see how to save store lables.

As we can see, we can insert data into table eav_attribute_label directly.

$bind = ['attribute_id' => $object->getId(), 'store_id' => $storeId, 'value' => $label];
$connection->insert($this->getTable('eav_attribute_label'), $bind);