cancel
Showing results for 
Search instead for 
Did you mean: 

Insert attribute options (values) in bulk

Insert attribute options (values) in bulk

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.

 

color_attribute_backend.jpg

 

Thanks

 

3 REPLIES 3

Re: Insert attribute options (values) in bulk

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.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Insert attribute options (values) in bulk

Re: Insert attribute options (values) in bulk

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!