Magento Delete Attribute Values

In Project Some Attribute option value is to large and it’s difficult to delete by admin panel . because it take more time to delete via admin panel. Below Script is tell you how to Delete Drop Down Attribute option Values in fastest way..
This Script is only delete Attribute option Values not Attribute.
//Please take DB backup first.


<?php

require_once 'app/Mage.php';
umask(0);
Mage::app();

$tablePrefix = (string) Mage::getConfig()->getTablePrefix();
$db_read = Mage::getSingleton('core/resource')->getConnection('core_read');
$db_write1 = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = 'SELECT option_id FROM `'.$tablePrefix.'eav_attribute_option` WHERE attribute_id=92'; // Here 92 is COLOR Attribute Id 

//You can find Attribute Id (Catalog>> Attributes >> Manage Attributes) in admin panel
//Please put your Attribute Id in place of 92 in both place.

$data = $db_read->fetchAll($sql);
    
    foreach ($data as $key=>$val) {

	// Here we Delete COLOR Drop Down Attribute option Values

        if($val['option_id']){
 	   echo $sql1 = 'DELETE FROM `'.$tablePrefix.'eav_attribute_option_value` WHERE option_id='.$val['option_id'];
           echo '<br>';
           $db_write1->query($sql1);  
 
	   echo $sql2 = 'DELETE FROM `'.$tablePrefix.'eav_attribute_option` WHERE attribute_id=92 AND option_id='.$val['option_id'];
           $db_write1->query($sql2);   
           echo '<br>';
        }
   }
?>

Leave a Reply