1

I am creating one module for the custom product attribute and i want to add values in dropdown from the database.

I am using this code for adding vaules in dropdown:

public function getOptionText($value) {
    $value = Mage::getSingleton('core/resource')->getConnection('core_wri‌​te');
    $result = $value->query("select * from upload_image_upload");
    while ($row = $result->fetch() ) {
        $ids[]=$row['image'];
    }
    $options = $this->getAllOptions(false);
    foreach ($options as $item) {
        if ($item['value'] == $value) {
            return $item['label'];
        }
    }
    return false;
}
10
  • Can you please tell us in detail what you have tried and what you want to achieve? Commented Sep 7, 2016 at 11:07
  • I am trying to add values in to dropdown attribute from the database table rather than this "value 1", "value 2" etc.. Commented Sep 7, 2016 at 11:12
  • can you help me please? Commented Sep 7, 2016 at 11:12
  • do you want code for that or you want to add directly in database? Commented Sep 7, 2016 at 11:16
  • Though source model you can add options.This source model call in to your setup file " envisionecommerce.com/…" see this may it will usefull not sure
    – Pawankumar
    Commented Sep 7, 2016 at 11:18

2 Answers 2

1

you can try below code

where $option contains array like this

$options[0]= array("label"=>$label,'value'=>$value)

$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();
6
  • i do not want to add data like above code. i want to add data in dropdown from the other table like "upload_image_upload".means fetch data from this table and that fetched data should be add as value in dropdown attribute Commented Sep 7, 2016 at 12:21
  • So this is your duplicate question as before?? Commented Sep 7, 2016 at 12:22
  • yes i have face this problem from last week . can you help me ? Commented Sep 7, 2016 at 12:24
  • Dont ask same question again and again if you had try anything then post otherwise there is no mean to ask same question again and again Commented Sep 7, 2016 at 12:25
  • oh... than you can tell me that you have no idea about this. Commented Sep 7, 2016 at 12:36
0

This is not a correct way to add values. But if you want to add with database you have to add values in 2 tables 'eav_attribute_option' and 'eav_attribute_option_value'.

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