Magento – How to update attribute frontend labels programmatically

magento-2.1magento2

I have the code:

 $attributeModel = \Magento\Framework\App\ObjectManager::getInstance()
        ->get(\Magento\Eav\Model\Attribute::class)->load($id);

And I have to create/update frontend labels of $attributeModel for another stores (French & German)

Or maybe I should use another methods?

enter image description here

Best Answer

Try this code, it will change default label

$attributeModel = \Magento\Framework\App\ObjectManager::getInstance()
      ->get(\Magento\Eav\Model\Attribute::class)->load(140);

  $attributeModel->setData('frontend_label',{Your_value});
  $attributeModel->save();

For store wise label set

$currentdata= $attributeModel->getStoreLabels();
$currentdata[{StoreID}] = {New Label for store};
$attributeModel->setData('store_labels',$currentdata);
$attributeModel->save();
Related Topic