Magento 2: Is there any way to add bulk option add in attribute?
-
30-12-2020 - |
Question
I have list of option value for attribute, But i just need to save this value in attribute at one time .
i already used below script, using this script i have to save attribute on every new option add.
$languageValues[0] = $item;
$attr = $objectManager->create('\Magento\Eav\Model\Entity\Attribute');
$attr->load($attributeShopbyID->getId());
$option = array();
$option['value']['shopbyattribute'] = $languageValues;
$attr->addData(array('option' => $option));
$attr->save();
instead of saving attribute every time i just need to save all option at once.
Solution
Below solution is work for me :
$languageValues[0] = $item;
$attr = $objectManager->create('\Magento\Eav\Model\Entity\Attribute');
$attr->load($attributeShopbyID->getId());
$option = array();
$option['value']['shopbyattribute'.$i] = $languageValues;
$attr->addData(array('option' => $option));
$attr->save();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange