1

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

0
$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

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

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:

http://inchoo.net/magento/how-to-create-custom-attribute-source-type/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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