tuan
9/1/2015 - 8:00 AM

Save a list of option for Attribute Model #Magento #EAV #OPTION

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();