Hi,
I created a custom drop down attribute in magento 2 and i hundreds of options to add in the attribute. What is the best way to add in bulk, maybe using a csv file or using direct query.
Thanks
Your best way is using Direct sql query.
You cant do within csv file to import multiple option of attribute because there are not native code for that using csv.
You have to refer below link to using sql query,
Insert multiple option value of attribute.
If issue solved, Click Kudos/Accept As Solutions.
Follow this Link to do so "https://www.pearlbells.co.uk/import-attribute-options-magento-2-programmatically/"
Hi@abdulwahab1290 ,
You can add custom options programmatically using following code.
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterface $customOption */ $customOption = $this->objectManager->create('Magento\Catalog\Api\Data\ProductCustomOptionInterface'); $customOption->setTitle('Text') ->setType('area') ->setIsRequire(true) ->setSortOrder(1) ->setPrice(1.00) ->setPriceType('fixed') ->setMaxCharacters(50) ->setProductSku($product->getSku()); $customOptions[] = $customOption; $product->setOptions($customOptions)->save();
I hope it will help you!