Jun 15, 2013
kalpesh

Magento get list of all product attributes

Get list of all the product attributes defined in Magento. This will fetch you an array with all the attribute codes as a key AND all the attribute details including attribute code as a value. You can limit this array by just attribute code and attribute label as per your need. I will show you all the possible attribute information you can fetch defined for the product.

1
2
3
4
5
6
7
$attrib_data = array(); $allAttributeCodes = array();
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')->getItems();

foreach ($attributes as $attribute){
    $attrib_data[$attribute->getAttributeCode()] = $attribute->getData();
    //$allAttributeCodes[] = $attribute->getAttributeCode();
}

Sample Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Array(
	[color] => Array
        (
            [entity_type_id] => 10
            [attribute_code] => color
            [attribute_model] => 
            [backend_model] => 
            [backend_type] => int
            [backend_table] => 
            [frontend_model] => 
            [frontend_input] => select
            [frontend_label] => Color
            [frontend_class] => 
            [source_model] => 
            [is_required] => 0
            [is_user_defined] => 1
            [default_value] => 
            [is_unique] => 0
            [note] => 
            [attribute_id] => 272
            [frontend_input_renderer] => 
            [is_global] => 1
            [is_visible] => 1
            [is_searchable] => 1
            [is_filterable] => 1
            [is_comparable] => 1
            [is_visible_on_front] => 0
            [is_html_allowed_on_front] => 0
            [is_used_for_price_rules] => 1
            [is_filterable_in_search] => 1
            [used_in_product_listing] => 0
            [used_for_sort_by] => 0
            [is_configurable] => 1
            [apply_to] => simple
            [is_visible_in_advanced_search] => 1
            [position] => 1
            [is_wysiwyg_enabled] => 0
            [is_used_for_promo_rules] => 1
        )
	[other_attribute_code] => Array 
	(						
		....
	)
)

Now you can easily access all the attribute information from the above array.

2 Comments

  • Hi,
    Thanks,
    I really enjoy the blog.Much thanks again. Great.

  • Thank you for this post. I wasn’t able to view all my 72 attributes untill now.

    Cheers

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications