Delete attribute options magento 1

This tutorial explains how to delete attribute options magento 1 programmatically.The script get all the attribute options and delete the options as shown below.

Please also refer the tutorial explains how to import attribute options magento 2 programmatically and other magento tutorials.


delete_attribute_options_magento_1
delete_attribute_options_magento_1_9

Step by step explanation

  • Initialise script
  • Delete attribute options magento

Delete attribute options magento 1

The script get all the attribute options from the attribute ‘color’ and delete programmatically.

<?php
require_once '../app/Mage.php';
ini_set('display_errors', 1);
Mage::app('admin');
Mage::setIsDeveloperMode(true);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
deleteAttribute();

function deleteAttribute() {
    
    $attr = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');
    $options = $attr->getSource()->getAllOptions();
    array_shift($options);
    
    foreach ($options as $option) {
        
        echo 'Delete option : '.$option['label'].PHP_EOL;  
        $options['delete'][$option['value']] = true; 
        $options['value'][$option['value']] = true;
    
    }

    $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
    $setup->addAttributeOption($options);
    
}

Please also refer the tutorial explains how to import attribute options magento 2 programmatically and other magento tutorials.

Share this Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *

*