views:

68

answers:

2

I have set an attribute set in my Magento shop which has several binary attributes.

For a pulldown I need a list of ALL the attributes inside this one attribute set, including their internal name and their label. Since this pulldown should appear in places that not necessarily have a product selected I can't go the usual route of "getting the attributes of a product".

How do I go about of getting a list of all the attributes inside my set?

A: 

Hi,

try this snippet, it should give you want you need, except for multi-select attributes.

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product','attribute_name');
    foreach($attribute->getSource()->getAllOptions(true,true) as $option){
        $attributeArray[$option['value']] = $option['label'];
    }
    return $attributeArray;

Hope this helps, JD

Jonathan Day
Nope, just returns me an empty array. :(
Sorcy
+1  A: 

OK, I realised that I missed that you want the whole set of attributes, not just an individual one. Try this:

$attributesInfo = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter('4')  //4 = product entities
->addSetInfo()
->getData();

You'll then need to iterate through the array that is returned with something like:

foreach($attributesInfo as $attribute):
    $attribute = Mage::getModel('eav/entity_attribute')->load($attribute['attribute_id']);
    echo 'label = '.$attribute->getFrontendLabel().'<br/>';
    echo 'code = '.$attribute->getAttributeCode().'<br/><br/>';
endforeach;

Sorry for missing the original point, hope this helps!

Cheers, JD

Jonathan Day
Much better. When I use your code I get a list of attributes, but not my custom ones. I got those by switching "->setEntityTypeFilter" from 4 to 10, even though I'm not sure why 10. I just got there by randomly trying. :)Thanks anyway.
Sorcy
No problem. You should be able to find the id of your entity by looking in the eav_entity_type table in the db. Looks like 10 = sales/quote_payment, at least in Mage v1.4.1Pleased that it worked for you :)JD
Jonathan Day