Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tuanphpvn/e7c4bf8d4da477ae993a to your computer and use it in GitHub Desktop.
Save tuanphpvn/e7c4bf8d4da477ae993a to your computer and use it in GitHub Desktop.
Save a list of option for Attribute Model #Magento #EAV #OPTION
<?php
$genders = array();
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'gender'); // "gender" is attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
<?php
$updateAttributeOptionValue = function() {
$attribute_model = Mage::getModel('eav/entity_attribute');
$attribute_id = $attribute_model->getIdByCode('catalog_product', 'color');
$attribute = $attribute_model->load($attribute_id);
$arrColor = array(
'Brown',
'Charcoal',
'Green',
'Grey',
'Idigo',
'Ivory',
'Khaki',
'Oatmeal',
'Orange',
'Pink',
'Purple',
'Royal Blue',
'Silver',
'Taupe',
'White',
'Yellow'
);
$value['option'] = $arrColor;
$result = array('value' => $value);
$attribute->setData('option',$result);
try {
$attribute->save();
}
catch(Exception $e) {
echo $e->getMessage();
}
};
//$updateAttributeOptionValue();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment