I have the following code, but it displays all attribute options. I want to only display those that have been assigned to a product. What would I change to do this?
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $id);
foreach ( $attribute->getSource()->getAllOptions(true) as $option){
echo $option['label'];
}
getAllOptionsreturns an array whereas we need a collection or query to work with. This first part joins that collection with the relevant attribute table, normally it’s not a good idea to be doing this manually so be careful.Now you can just step through the options,
…or convert to array to get back where you started.