One of the things that a Magento developer deal, time and again is finding out all the options of color or manufacturer or size attribute. You may also need to find out what are the options available for color attribute before you add new option programmatically. Or you may need to add assign the option’s ID to a product. Here’s what you need to do, just load the attribute by attribute code, then load all its options. Easy, isn’t it! Code is below.
// Add the attribute code here.
$attribute=$product->getResource()->getAttribute("color");
// Checking if the attribute is either select or multiselect type.
if($attribute->usesSource()){
// Getting all the sources (options) and print as label-value pair
$options = $attribute->getSource()->getAllOptions(false);
echo "<pre>";
print_r($options);
}

Thanks for the tip Subesh. I’ve been having some issues with a similar issue. Whenever I try to list or filter “multiple select” based attributes, I get a blank page. The following based on a “textfield” attribute for example, works fine. Whenever I enter the code of a “multiple select” attribute, it stops from working. I appreciate if you can pass a hint of a solution. Happy New Year!
getCollection();
$collection->addAttributeToSelect(’name’); //multiple select attributes fail
$collection->load();
?>
<a href="getProductUrl() ?>”>getName() ?>
One more time. Really sorry. Don’t know how enclose the code. Not working.
$model = Mage::getModel(’catalog/product’);
$collection = $model->getCollection();
$collection->addAttributeToSelect(’name’); //multiple select attributes fail
$collection->load();
@Magento Fan
$collection = $model->getCollection()
->addAttributeToSelect(”color”) ->addAttributeToFilter(”color”,’15′);
$collection->load();
You can work like this..
@subesh
Refering to the code you posted first.
Is there also a way to not show all the attributes of a product?
Or better in my case, Only the attribute ’size’ that is out of stock?
best regards
In Frontend? or Backend…
// Add the attribute code here.
$attribute=$product->getResource()->getAttribute(”color”);
// Checking if the attribute is either select or multiselect type.
if($attribute->usesSource()){
// Getting all the sources (options) and print as label-value pair
$options = $attribute->getSource()->getAllOptions(false);
echo “”;
print_r($options);
}
form this i am egtting pair of option but I need only value of option..what i will do
This should fix your problem
$_attribute=$_product->getResource()->getAttribute(”size”);
$_sourceTable = Mage::getModel(’eav/entity_attribute_source_table’)->setAttribute($_attribute);
$_sizeText = $_sourceTable->getOptionText($_product->getSize());
Thank You . It’s solve my problem