magentoattributesmagento-1.9

How do I get attribute set name?


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.


Solution

  • 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');
    }