php - How to add attribute option label and value in magento by coding? -
i add, update , delete magento product attribute option value , label ? not admin coding....
thanks in advance..
hello all, got it.
here have product attribute name manufacturer , add new manufacturer "adidas" coding. below snippet same.
also can delete attribute option value coding.
<?php // add new option in manufacturer attribut coding 'adidas' in manufacturer attribute $attribute_code=mage::getmodel('eav/entity_attribute')->getidbycode('catalog_product', "manufacturer"); $attributeinfo = mage::getmodel('eav/entity_attribute')->load($attribute_code); $attribute_table = mage::getmodel('eav/entity_attribute_source_table')->setattribute($attributeinfo); $options = $attribute_table->getalloptions(false); //$options = $attributeinfo->getsource()->getalloptions(false); $_optionarr = array('value'=>array(), 'order'=>array(), 'delete'=>array()); foreach ($options $option){ $_optionarr['value'][$option['value']] = array($option['label']); $checkarray[] = $option['label']; } if (!in_array('adidas', $checkarray)) { $_optionarr['value']['option_1'] = array('adidas'); $attributeinfo->setoption($_optionarr); $attributeinfo->save(); } //delete option manufacturer 'adidas' $attribute_code=mage::getmodel('eav/entity_attribute')->getidbycode('catalog_product', "manufacturer"); $attributeinfo = mage::getmodel('eav/entity_attribute')->load($attribute_code); $attribute_table = mage::getmodel('eav/entity_attribute_source_table')->setattribute($attributeinfo); $options = $attribute_table->getalloptions(false); //$options = $attributeinfo->getsource()->getalloptions(false); $_optionarr = array('value'=>array(), 'order'=>array(), 'delete'=>array()); foreach ($options $option){ $_optionarr['value'][$option['value']] = array($option['label']); if('adidas' == $option['label']){ $_optionarr['delete'][$option['value']] = true; } } $attributeinfo->setoption($_optionarr); $attributeinfo->save(); ?>
Comments
Post a Comment