Saturday, 26 January 2013

Programmatically add attributes's option in magento



$arg_attribute = '<attribute-code>';
$attr_model = Mage::getModel('catalog/resource_eav_attribute');
$attr = $attr_model->loadByCode('catalog_product', $arg_attribute);
$attr_id = $attr->getAttributeId();
$opt['attribute_id'] = $attr_id;
$opt['value']['<admin-value>'][0] = '<admin-name>'; //admin name of option
$opt['value']['<admin-value>']][1] = '<admin-name>'; //default store name of option

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeOption($opt);

2 comments:

  1. Please specify what you mean for ['admin-value']
    Thank you
    Giuseppe

    ReplyDelete
  2. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. Magento 2 Freelancers

    ReplyDelete