How do I get attribute set name?

Moon picture Moon · Jan 19, 2010 · Viewed 59.3k times · Source

I am trying to get attribute set name in Magento product view template. I can get attribute value by $_product->getAttributeText('attribute'), but how do I get attribute set name?

I would like to display an attribute only if it is belong to a certain attribute set.

Answer

Joseph Mastey picture Joseph Mastey · Jan 19, 2010

Whenever you have a product object, you can access its attribute set like this:

$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
$attributeSetModel->load($product->getAttributeSetId());
$attributeSetName  = $attributeSetModel->getAttributeSetName();

This will give you the name of the attribute set, which you can then compare using strcmp:

if(0 == strcmp($attributeSetName, 'My Attribute Set')) {
    print $product->getAttributeText('attribute');
}

Hope that helps!