Menu Close
    Hire us Request quote Reading list Switch to dark mode
    lockdownWebkulUp

    Create drop down product attribute in Magento 2

    Today  I am going to explain, how we can create drop down attribute for Products in Magento 2.
    There are two ways to create the drop down attribute in Magento.
    1 -> Manually : Go To admin panel,  Store -> Attributes -> Product .
    2 -> Programmatically .

    In this blog I am covering how we can create the drop down attribute programmatically,
    So let’s start :
    Step 1 : create InstallData.php file : Company\Module\Setup\InstallData.php
    Now In this file, create an Array of the attributes that you want to add as below.


    Step 2 : Now Add and Assign Attribute to Group and Attribute Set.



    . . .
    Subscribe Articles

    Just enter your email below to subscribe and receive weekly updates about the most interesting similar articles.

    You need to accept conditions to receive letters.
    You've Subscribed!

    Share article via

    . . .

    Note :
    $attributeSet : you can load the attribute collection and loop for it or Can pass specific id instead.
    $groupId : Magento\Eav\Model\Entity\Attribute\Group : you can get the group id with the help of this class.

    Now , Options for drop down attribute , you can add options directly as a array.
    and another approach is to use class Magento\Eav\Model\Entity\Attribute\Source\AbstractSource  as follows :


    Please read each line carefully, so that you can create the attributes easily.
    and In case you have any Query then feel free to ask in comment section below.

    . . .

    Comments (2)

    Add Your Comment

  • Senthil
    Step 2 is not clear
    • Prabhat Rawat
      I have added classes in comment for second step, that I thing you might be confused with.
      If there is any thing else with which you are confused, that I have missed to explain so please explain in more details.

      In second step, we have just added and assigned the attribute to the attribute set and group.

  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close