Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alvinnguyen/a8881c9a60f48a9eda88ef8f361d605b to your computer and use it in GitHub Desktop.
Save alvinnguyen/a8881c9a60f48a9eda88ef8f361d605b to your computer and use it in GitHub Desktop.
Magento PHP script to delete all values of an attribute
<?php
$attribute_code = 'fashion_colour';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
$options = $attribute->getSource()->getAllOptions();
$optionsDelete = array();
$optionsValue = array();
foreach($options as $option) {
if (in_array($option['label'], $optionsValue)) {
$optionsDelete['delete'][$option['value']] = true;
$optionsDelete['value'][$option['value']] = true;
} else {
$optionsValue[] = $option['label'];
}
}
var_dump($optionsDelete);
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->addAttributeOption($optionsDelete);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment