Magento create dropdown from product attribute option

Here a simple but complete example to create a dropdown list for a product attribute

//retrieve informations
$attribute_model        = Mage::getModel('eav/entity_attribute');
$attribute_code         = $attribute_model->getIdByCode('catalog_product', 'audience');
$attribute              = $attribute_model->load($attribute_code);
$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;
$attribute_table        = $attribute_options_model->setAttribute($attribute);
$options                = $attribute_options_model->getAllOptions(false);

//display them
echo '<select id="audience" class="select" name="audience">';
foreach($options as $option)
{
    echo '<option value="'.$option['value'].'">'.$helper->__($option['label']).'</option>';
}
echo '</select>';

Leave a Reply