Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

magento

Having an attribute set, how can I get a list of the attributes it contains (or better yet, just the custom attributes that don't belong to the Default attribute set)?

The attribute set itself can be obtained in several ways, such as:

$entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
$attributeSet = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter($entityTypeId)->addFilter('attribute_set_name', 'Default');

Note that I need to use the attribute set, so getting the list of attributes from a product is not the solution I am looking for.

like image 601
Epicurus Avatar asked Jul 27 '11 09:07

Epicurus


3 Answers

Mage::getModel('catalog/product_attribute_set_api')->items();

Gets the attribute sets themselves.

Mage::getModel('catalog/product_attribute_api')->items($setId);

Gets the attributes inside the attribute sets.

like image 69
elcash Avatar answered Oct 02 '22 18:10

elcash


I believe the answer lies in this model

Mage::getModel('catalog/product_attribute_set_api')->items($setId);

The class is Mage_Catalog_Model_Product_Attribute_Api it seems to have two methods. The items() methods seems to do what you ask i.e. "Retrieve attributes from specified attribute set"

I hope that helps :)

like image 43
Gabriel Spiteri Avatar answered Oct 02 '22 17:10

Gabriel Spiteri


The right way:

$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->setAttributeSetFilter($attributeSetId)
->getItems();
var_dump($attributes);

You can change resources 'catalog/product_attribute_collection' (customer, ...) And Set ID $attributeSetId

like image 28
Imaginaerum Avatar answered Oct 02 '22 16:10

Imaginaerum