0

How to save programatically attribute option value in Default Store View in attribute in magento 1.9?

public function saveAttributeValueAction()
    {   
        $arg_attribute = 'ram';
        $file_handle = fopen('/var/www/dev/attributedata.csv', 'r');
        while (!feof($file_handle) ) 
        {
            $array_keyword_value[] = fgetcsv($file_handle, 1024);
        }
        fclose($file_handle);
        foreach ($array_keyword_value as $key1 => $value1) {
            $key_data[] = $value1[0];
        }
        $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
        $attr_model = Mage::getModel('catalog/resource_eav_attribute');
        $attr = $attr_model->loadByCode('catalog_product', $arg_attribute);
        foreach($key_data as $key_value)
        {   
         $option = array();
         $arg_value = trim($key_value);
         $attr_id = $attr->getAttributeId();
         $option['attribute_id'] = $attr_id;
         $option['value']['any_option_name'][0] = $arg_value;
         $setup->addAttributeOption($option);
        }
    }

I have to save value in attribute but not save in default store view. Please help me how to save it?

enter image description here

1 Answer 1

0

This is worked for me.

public function saveAttributeValueAction()
    {   
        $arg_attribute = 'ram';
        $file_handle = fopen('/var/www/dev/attributedata.csv', 'r');
        while (!feof($file_handle) ) 
        {
            $array_keyword_value[] = fgetcsv($file_handle, 1024);
        }
        fclose($file_handle);
        foreach ($array_keyword_value as $key1 => $value1) {
            $key_data[] = $value1[0];
        }
        $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
        $attr_model = Mage::getModel('catalog/resource_eav_attribute');
        $attr = $attr_model->loadByCode('catalog_product', $arg_attribute);
        foreach($key_data as $key_value)
        {   
         $option = array();
         $arg_value = trim($key_value);
         $attr_id = $attr->getAttributeId();
         $option['attribute_id'] = $attr_id;
         $option['value']['any_option_name'][0] = $arg_value;
         $option['value']['any_option_name'][1] = $arg_value;
         $setup->addAttributeOption($option);
        }
    }

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.