Monday 25 July 2016

How to add new option to attribute programatically Magento ?

   

we can easily do this witht the below peace of code. It will add a new option to the existing attribute.

   $arg_attribute = 'your_attribute_code'; // enter your attribute code here
        $arg_value = 'new option value';
        $attr_model = Mage::getModel('catalog/resource_eav_attribute');
        $attr = $attr_model->loadByCode('catalog_product', $arg_attribute);
        $attr_id = $attr->getAttributeId();
        $option['attribute_id'] = $attr_id;
        $option['value']['any_option_name'][0] = $arg_value;
        $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
        $setup->addAttributeOption($option);

No comments:

Post a Comment