Magento: how to get the attributes that belong to an attribute set?

Magento: how to get the attributes that belong to an attribute set?

July 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: how to get the attributes that belong to an attribute set?

Magento: How to Retrieve Attributes Belonging to an Attribute Set?

In Magento, attribute sets are used to group related product attributes together for easier management. If you have an attribute set and want to retrieve the list of custom attributes it contains (excluding those from the Default set), this guide will show you how.

Understanding Attribute Sets in Magento

Before diving into the code, let’s briefly understand what attribute sets are in Magento:

  • An attribute set is a collection of product attributes.
  • Each product can belong to an attribute set.
  • You can create multiple attribute sets to group related attributes together.

For example, you might have Default as your base attribute set containing common fields like sku, price, and name. Then you could create custom sets like Electronics or Clothing for specific product categories with additional, relevant attributes.

Retrieving Attributes from an Attribute Set

To retrieve the list of attributes belonging to a specific attribute set, we’ll need to use Magento’s EAV (Entity-Attribute-Value) model. Here’s how you can do it:

  1. First, get the entity type ID for catalog_product:
$entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
  1. Then, create a collection of attribute sets and filter by the desired set name:
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
    ->setEntityTypeFilter($entityTypeId)
    ->addFilter('attribute_set_name', 'Your_Custom_Set_Name');

Replace 'Your_Custom_Set_Name' with the actual name of your custom attribute set.

  1. Now, retrieve the attributes from the filtered attribute set:
$attributes = $attributeSetCollection->getFirstItem()->getAttributes();

The $attributes variable now contains an array of Mage_Catalog_Model_Resource_Eav_Attribute objects representing all the custom attributes in your specified set.

Excluding Default Set Attributes

If you want to exclude attributes from the Default set (which contain common fields like sku, price, and name), you can add a condition:

$attributes = $attributeSetCollection->getFirstItem()->getAttributes();
$customAttributes = array_filter($attributes, function ($attr) {
    return $attr->getEntityTypeId() != 'catalog_product' && $attr->getAttributeCode() != 'entity_id';
});

This code excludes the catalog_product entity type (which contains Default set attributes) and ensures we don’t include system fields like entity_id.

Conclusion

Retrieving custom attributes from a specific Magento attribute set is relatively straightforward once you understand how to work with EAV models. By following this guide, you can easily access and manage the product attributes that matter most for your business.

Remember to replace placeholders like 'Your_Custom_Set_Name' with your actual attribute set names.

For more advanced Magento tutorials and tips, be sure to check out our blog at https://laravelcompany.com/magento-blog. We regularly publish articles on topics like theme customization, extension development, and performance optimization.

Catalog Pricing

Our network