Magento 1.9 – Create Dropdown Attribute for Products

databasemagento-1.9product-attribute

I want to create Dropdown Attribute for Products and want to fetch data from the database in created Dropdown Attribute.

Best Answer

$attribute = Mage::getModel('eav/config')->getAttribute( Mage_Catalog_Model_Product::ENTITY ,'attribute_code');
        $options = $attribute->getSource()->getAllOptions();
        print_r ($options);

<select name="some name">
<?php foreach($options as $option): ?>
  <option value="<?php echo $option['value'] ?>"><?php echo $option['label'] ?></option>
 <?php endforeach;?>
</select>

My updated answer to you

load your table collection by $coll = Mage::getModel('yourModel')->getCollection();

And foreach loop in your collection add all your option in $option as lable and value pair for each option

$attribute_model        = Mage::getModel('eav/entity_attribute');
$attribute_code         = $attribute_model->getIdByCode('catalog_product', 'your_attribute_code');
$attribute              = $attribute_model->load($attribute_code);
 $attribute->setData('option',$option);
        $attribute->save();

Try above code and let me know if it is not working

Related Topic