I have an attribute that has thousands of options. The options are created programmatically by a script that imports all my products from a feed. The site is running pretty slow, so I figured I'd get rid of all the outdated options. The problem is that I'm unable to load the edit page form the magento admin. How can I identify the attribute options with a MySQL query? Or how can I delete all the attribute options programmatically?
Thanks!
this will give you the list of all options
$attribute_code = 'color';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product',$attribute_code);
$options = $attribute->getSource()->getAllOptions();
and this allows you to update attribute and remove options
$options['delete'][$option_id] = true;
$options['value'][$option_id] = true;
$options['delete'][$another_option_id] = true;
$options['value'][$another_option_id] = true;
// (...)
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttributeOption($options);
Here, I am explain you 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.
<?php
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');
$installer->addAttributeOption($optionsDelete);
?>
I hope it will help you. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With