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

2 Answers 2

$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;?>

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);

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

  • i want to data in the dropdown from the database. Commented Sep 1, 2016 at 11:38
  • It will give you all option and you can add options using foreach loop Commented Sep 1, 2016 at 11:41
  • it gives output like this Array ( [0] => Array ( [label] => [value] => ) ) Commented Sep 1, 2016 at 11:53
  • It has attribute data or not? Commented Sep 1, 2016 at 11:55
  • in my attribute there is no data Commented Sep 1, 2016 at 11:56

You need to create a source model (like like Mage_Tax_Model_Class_Source_Product) as well as an attribute that uses the source model.

In the source model you need to query the table and return the results in the getAllOptions function.

You can look here for a guide:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.