Add drop down list attribute to category - set source

Add drop down list attribute to category - set source

October 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add drop down list attribute to category - set source

[BLOG POST]

Adding a Drop Down List Attribute to Category with Correct Source

As an e-commerce developer working with Magento, you might find yourself needing to add new attributes to your product categories using drop-down list sources from existing attributes. In this blog post, we’ll walk through the process of adding a category attribute that pulls its options from the ‘brand’ attribute of products.

Understanding the Problem

You’ve already added the ‘brand’ attribute to your products with a drop-down list source. Now you want to add a similar attribute to your categories called ‘brands’, whose values will come from the pre-defined ‘brand’ options in your product attribute set. However, when you attempt this, you encounter an error: “Source model ‘mymodule/selectattributes’ not found for attribute ‘brands’.”

The error suggests that Magento is looking for a specific source model to populate the drop-down list for your category’s new ‘brands’ attribute, but it cannot find it. This is because when you added the ‘brand’ attribute to products, Magento automatically created its own source model—Mage_Eav_Model_Entity_Attribute_Source_Boolean. You need to create a similar model for your category’s ‘brands’ attribute.

Creating the Source Model

To solve this issue, you’ll need to create a custom source model that extends Mage_Eav_Model_Entity_Attribute_Source_Abstract. This model should fetch all options from the existing ‘brand’ attribute of products and return them as an array.

Here’s how to do it:

class MyPackage_MyModule_Model_SelectAttributes extends Mage_Eav_Model_Entity_Attribute_Source_Abstraction {
    public function getAllOptions()
    {
        $attributeCode = 'brand';

        $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attributeCode);
        $allOptions = $attribute->getSource()->getAllOptions(true, true);

        foreach ($allOptions as $instance) {
            $myArray[$instance['value']] = $instance['label'];
        }

        return $myArray;
    }
}

In this code:

  1. We define a new model MyPackage_MyModule_Model_SelectAttributes that extends the abstract source model.
  2. The getAllOptions() method is overridden to fetch all options from the ‘brand’ product attribute.
  3. We use Magento’s EAV configuration model (Mage::getModel('eav/config')) to retrieve the ‘brand’ attribute and its source.
  4. We call the getSource()->getAllOptions(true, true) method on the attribute object to fetch all options, including disabled ones.
  5. The fetched options are looped through and added to a new array $myArray.

Adding the Category Attribute

Now that we have our custom source model, let’s add the ‘brands’ drop-down list attribute to categories:

    $this->startSetup();
    $this->addAttribute('catalog_category', 'brands', array(
        'group'                => 'General',
        'type'                 => 'int',
        'backend'              => '',
        'frontend_input'       => 'select',
        'frontend'             => '',
        'label'                => 'Brands',
        'input'                => 'select',
        'class'                => '',
        'source'               => 'mymodule/selectattributes',
        'global'               => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible'              => true,
        'frontend_class'       => '',
        'required'             => false,
        'user_defined'         => true,
        'default'              => '',
        'position'             => 100,
    ));
    $this->endSetup();

In this setup script:

  1. We use the addAttribute() method to create a new attribute for categories.
  2. The attribute code is set to ‘brands’.
  3. The ‘source’ parameter points to our custom source model ‘mymodule/selectattributes’.

Conclusion

Adding drop-down list attributes with pre-defined options from existing product attributes requires a careful setup of the EAV configuration in Magento. By creating a custom source model and using it as the source for your category attribute, you ensure that the options are correctly fetched and displayed.

Remember to clear the cache after making these changes for them to take effect in the Magento admin panel.

For more detailed information on Magento’s EAV architecture and how to work with attributes, consider checking out our comprehensive guide on Magento EAV at Laravel Company.

Catalog Extensions Errors

Our network