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

magento.stackexchange https://magento.stackexchange.com/questions/240502

سؤال

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

هل كانت مفيدة؟

المحلول

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);
        }
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top