How to Delete All Attribute Option Value Programmatically in Magento


Here, I am explaining about how to delete all attribute option value programmatically in magento. you can also delete the attribute option value from the admin panel of the magento but if there are so many attribute option value then it takes so much time to delete from the admin so you can add attribute option value programmatically in magento. For that you just need to create deleteattributeoptions.php file in your magento root folder add put below code in it And Replace the ATTRIBUTE_CODE_HERE with your attribute code.


require_once ‘app/Mage.php’;$app = Mage::app(‘admin’);umask(0);
$attribute_code = ‘ATTRIBUTE_CODE_HERE‘;
$attribute = Mage::getModel(‘eav/config’)->getAttribute(‘catalog_product’, $attribute_code);
$options = $attribute->getSource()->getAllOptions();
$optionsDelete = array();
foreach($options as $option) {
if ($option[‘value’] != “”) {
$optionsDelete[‘delete’][$option[‘value’]] = true;
$optionsDelete[‘value’][$option[‘value’]] = true;
$installer = new Mage_Eav_Model_Entity_Setup(‘core_setup’);


Thanks for reading my blog. I hope it will help you, Please leave your comments here if it’s really help you. 🙂

Thank You :),
Mayank Zalavadia