---
title: "How to add attribute options values into dropdown attribute programmatically"
url: "https://dolphinwebsolution.com/how-to-add-attribute-options-values-into-dropdown-attribute-programmatically"
date: "2023-06-17T12:33:42+05:30"
modified: "2023-08-29T06:28:44+05:30"
author:
  name: "Jigar Patel"
categories:
  - "Magento2"
  - "Magento"
word_count: 548
reading_time: "3 min read"
summary: "In Magento 2, attribute options are used to define the selectable values for dropdown, multiselect, and other similar attributes. These options allow you to provide predefined choices for customers..."
description: "In Magento 2, attribute options are used to define the selectable values for dropdown, multiselect, and other similar attributes. These options allow you to ..."
keywords: "attribute options,attribute,csv,programmatically, Magento2, Magento"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How Much Does It Cost To Hire A Magento Developer?"
    url: "https://dolphinwebsolution.com/blog/cost-to-hire-magento-developer/"
  - title: "Add Custom Select Options Attribute in Category Form Magento 2"
    url: "https://dolphinwebsolution.com/add-custom-select-options-attribute-in-category-form-magento-2"
  - title: "Remove Products with Duplicate SKU from Magento2"
    url: "https://dolphinwebsolution.com/remove-products-with-duplicate-sku-from-magento2"
---

# How to add attribute options values into dropdown attribute programmatically

_Published: June 17, 2023_  
_Author: Jigar Patel_  

![How to add attribute options values into dropdown attribute programmatically](https://dolphinwebsolution.com/wp-content/uploads/2023/06/Frame-215-1024x536.png)

In Magento 2, attribute options are used to define the selectable values for dropdown, multiselect, and other similar attributes. These options allow you to provide predefined choices for customers when they are selecting attribute values for products.

**Add attribute options values into a dropdown attribute in the Magento 2 Admin panel, following these steps:**

1. Log in to your Magento 2 Admin panel.
2. Navigate to **Stores** -> **Attributes** -> **Product**.
3. Find the attribute you want to modify and click on its row to edit it.
4. Scroll down to the **Manage Labels/Options** section.
5. Under the **Options** tab, you’ll see a list of existing attribute options (if any). To add a new option, click on the **Add Option** button.
6. In the **Option Value** field, enter the label for the new option. For example, if you want to add an option “Option 1”, enter “Option 1” in the field.
7. If you want to assign a specific value to the option, you can enter it in the **Sort Order** field. Otherwise, Magento will assign a value automatically.
8. Click on the **Save Attribute** button to save the changes.
9. Repeat steps 5-8 for each additional option you want to add.
10. Once you’ve added all the desired options, click on the **Save Attribute** button to save the attribute.

The attribute options you added will now be available in the dropdown attribute when you create or edit products in the Magento 2 Admin panel. Remember to clear the cache if necessary to see the changes immediately.

**Add attribute options values into an exits dropdown attribute in Magento 2 programmatically using CSV, you can follow these steps:**

1. Create **CSV** with color and attribute values as shown below & keep your CSV at **colorOptions.csv**

![Best AI Agent Development Companies in India (2026)](https://dolphinwebsolution.com/wp-content/uploads/2023/06/colorOptions-150x150.png)

2. Create **colorsAttribute.php** at Magento 2 root directory and paste the below code & execute the script using the **command line**

```
<?php

    ini_set('display_errors', '1');
    ini_set('error_reporting', E_ALL);

    use Magento\Framework\App\Bootstrap;
    require __DIR__ . '/app/bootstrap.php';

    $bootstrap = Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $entityType = 'catalog_product';
    $directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
    $path  =  $directory->getRoot().'/scripts/';
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
    $eavConfig = $objectManager->get('\Magento\Eav\Model\Config');
    $eavSetup = $objectManager->get('\Magento\Eav\Setup\EavSetup');
    $storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface');
    $stores = $storeManager->getStores();
    $storeArray[0] = "All Store Views";
    foreach ($stores  as $store)
    {
       $storeArray[$store->getId()] = $store->getName();
    }

    $fname = 'colorOption.csv';

    $file = fopen($path.$fname, "r");
    while (($data = fgetcsv($file, 100000, ",")) !== FALSE)
    {
        foreach((array)$data[0] as $attributeCode)
        {
        $option = array();
        $attribute = $eavConfig->getAttribute($entityType, $attributeCode);
        $option['attribute_id'] = $attribute->getAttributeId();
        $options = $attribute->getSource()->getAllOptions();
        if($data[1])
        {
        foreach((array)$data[1] as $key => $value)
        {
            $str = '"'.$value.'"';
            $option['value'][$str][0]=str_replace('"','', $str);
            foreach($storeArray as $storeKey => $store)
            {
              $option['value'][$str][$storeKey] = str_replace('"','', $str);
            }

        }

        $eavSetup->addAttributeOption($option);

        }
        }
    }
        fclose($file);

    echo "Attribute option values has been associated to color attribute SUCCESSFULLY";
```

3. run Re index from command line **php bin/magento indexer:reindex**

I Hope, This instruction will be helpful for you.
**Happy Coding with magento2!! ?**
If you have any difficulties regarding this blog, do consider posting them in the Comments section below!

I’m here to help.
Thank you!


---

_View the original post at: [https://dolphinwebsolution.com/how-to-add-attribute-options-values-into-dropdown-attribute-programmatically](https://dolphinwebsolution.com/how-to-add-attribute-options-values-into-dropdown-attribute-programmatically)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:14:06 UTC_  
