Nov 6, 2014
kalpesh

Magento: Get all attribute values (colors, sizes, etc..)

Magento get all the attribute values you have in the store. Get all the colors and sizes values in Magento. Change the attribute name to whatever you want values for, in the below script.

require_once('app/Mage.php');
umask(0);
Mage::app('admin');
//set_time_limit(0);
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');
$colors = array();
foreach ($attribute->getSource()->getAllOptions(true) as $option) {
        $colors[] = $option['label'];
}
sort($colors);
foreach($colors as $lbl) {
    echo "<span style='background-color:lightgrey'>".$lbl . "</span>";
        echo "<br>";
}

Replace color with any attribute you want to get values for. Above script also sorts the result set in alphabetic order to make it easy to view all values. If you don’t want to sort the values, just comment out the line which sorts it.

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

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions