How can I get a collection with the attribute sets that contain a certain attribute?
I want to be able do to this from a single collection walk (on single select), to avoid loading each attribute set and checking the attributes inside.
I know this seams like standard stuff, but I'm a bit slow these days.

4 Answers 4

        $attributeId = 96;
        $collection  = Mage::getModel('eav/entity_attribute_set')
            ->addFieldToFilter('eav_entity_attribute.attribute_id', $attributeId)
            ->addFieldToFilter('eav_entity_type.entity_type_code', Mage_Catalog_Model_Product::ENTITY)
            ->join(array('eav_entity_type'=> 'eav/entity_type'), 'eav_entity_type.entity_type_id=main_table.entity_type_id','entity_type_code')
            ->join(array('eav_entity_attribute'=> 'eav/entity_attribute'), 'eav_entity_attribute.attribute_set_id=main_table.attribute_set_id', 'attribute_id');
  • Works like a charm, nice one! Sep 18, 2013 at 13:42
  • Yep. Exactly what I needed.
    – Marius
    Sep 18, 2013 at 13:48

I found this right before @mageUz wrote the perfect answer. It's fast if you need only the attribute set ids. Maybe someone else needs it.

$attributeId = 123;
$setInfo = Mage::getResourceModel('eav/entity_attribute_set')
$attributeSetIds = array_keys($setInfo[$attributeId]);

I don't know how to do it with Magento objects but a direct query would work just as well I guess

SELECT  `eav_entity_attribute`.`attribute_set_id` 
FROM  `eav_attribute` ,  `eav_entity_attribute` 
WHERE  `eav_attribute`.`attribute_code` =  'cost'
AND  `eav_attribute`.`attribute_id` =  `eav_entity_attribute`.`attribute_id` 
  • Thanks. I found that table also. I guess I have to write my own resource model in order to use this query. +1, but I don't accept the answer yet. I'm hoping for a Magento solution
    – Marius
    Sep 18, 2013 at 13:15
  • Challenge accepted! If I'm home early tonight that is ^^ Sep 18, 2013 at 13:18

You can use below code to get all attribute of particular attribute set.

 $data =   Mage::getResourceModel('catalog/product_attribute_collection')
        ->setAttributeSetFilter(9) // Add attribute set ID
  • Thanks, but I think you misunderstood the question. I want the other way around. All ATTRIBUTE SETS that contain a certain ATTRIBUTE.
    – Marius
    Sep 18, 2013 at 12:22
  • sorry for the inconvenience. But I'll try to find magento solution. Sep 18, 2013 at 13:54
  • No problem. no inconvenience at all.
    – Marius
    Sep 18, 2013 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.