Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 398
Moon Avatar asked Jan 19 '10 05:01

Moon


People also ask

How can I get attribute set code in Magento 2?

You can retrieve the attribute set data by id in Magento 2 to know about attribute details. You can use Magento\Catalog\Api\AttributeSetRepositoryInterface to retrieve the attribute set info with get($attributeId) method. Output will be entity_type_id, attribute_set_name and sort order of the attribute set.

What is an attribute set?

Attribute sets can be defined as a list of attributes where all the characteristics of a product are demonstrated. For a new product the attribute set works as a template. Every product must belong to a specific attribute set which comes helpful in cases of: Dividing the products into groups.

What is attribute set ID in Magento?

Attribute set is a list of certain individual Magento product attributes, which fully describe all product's characteristics. Attribute set is used during every new product creation. This step lets one add all import information about the product in one step. By default, Magento includes 14 attribute sets.


1 Answers

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!

like image 163
Joe Mastey Avatar answered Sep 23 '22 13:09

Joe Mastey