Skip to content

Instantly share code, notes, and snippets.

@jonathansayag
Last active March 28, 2019 17:48
Show Gist options
  • Save jonathansayag/1cb15790feee0b773ebd to your computer and use it in GitHub Desktop.
Save jonathansayag/1cb15790feee0b773ebd to your computer and use it in GitHub Desktop.
Magento PHP script to delete all values of an attribute
<?php
$attribute_code = 'ATTRIBUTE_NAME';
$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);
?>
@bh-ref
Copy link

bh-ref commented Mar 11, 2016

Thank you for example, it helped me to do the same thing on Magento 2: https://gist.github.com/bh-ref/2a788f206f8c3d833e43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment