Haim Haim - 3 years ago 285
MySQL Question

Magento delete attribute values/options MySQL

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?


Answer Source

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');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download