Magento – Simple code snippet to remove redundant attribute from CLI

if you want to do something like this :

php -f remove_redundant_attribute.php

in order to remove redundant attributes, then this article is for you ๐Ÿ™‚ . yes, i know that Magento setup script is a headache sometime.

to do it, you just need to use the code snippet below for your ‘remove_redundant_attribute.php’ file

<?php
$mageFilename = getcwd() . '/app/Mage.php';

if (!file_exists($mageFilename)) {
    echo 'Mage file not found';
    exit;
}
require $mageFilename;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));

$installer = Mage::getResourceModel('catalog/setup', 'core_setup');
// remove the redundant attributes here
try {
    $installer->removeAttribute('catalog_product','seo_category');
}
catch (Exception $e) {
    echo $e->getMessage(); die;
}

to remove more attributes, please add more ‘$installer->removeAttribute(‘catalog_product’,’seo_category’);’

i hope you will find this article useful for you.

Leave a Comment