Skip to content

Instantly share code, notes, and snippets.

@ryantbrown
Last active April 10, 2016 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryantbrown/6d7cd6a6c2283efc911e to your computer and use it in GitHub Desktop.
Save ryantbrown/6d7cd6a6c2283efc911e to your computer and use it in GitHub Desktop.
Magento - Add attribute option
<?php
function addAttributeOption($attribute_code, $attribute_value) {
$attribute_model = Mage::getModel('eav/entity_attribute');
$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;
$attribute_code = $attribute_model->getIdByCode('catalog_product', $attribute_code);
$attribute = $attribute_model->load($attribute_code);
$attribute_table = $attribute_options_model->setAttribute($attribute);
$options = $attribute_options_model->getAllOptions(false);
$value['option'] = array($attribute_value,$attribute_value);
$result = array('value' => $value);
$attribute->setData('option',$result);
$attribute->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment