Magento-1.7 – How to Delete an EAV Product Attribute Programmatically

eavmagento-1.7product-attribute

i want to delete a product attribute from eav table pragmatically.
I was getting a code which was delete customer attribute.

I want just like this code ,which was delete product attribute.

<?php
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app();
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

    try {
        $custAttr = 'user_name';  // here enter your attribute name which you want to remove

        $setup->removeAttribute('customer', $custAttr);
        echo $custAttr." attribute is removed";
    }
        catch (Mage_Core_Exception $e) {
        $this->_fault('data_invalid', $e->getMessage());
    }

?>

please help me.

Best Answer

It is my view that this sort of thing should be done via set-up script or if that is not possible then via the admin section. I cannot think of a situation where you need to write a script for this, but maybe there is one.

For a set-up script it is incredibly simple:

$this->startSetup();
// Remove Product Attribute
$this->removeAttribute('catalog_product', 'product_attribute_code');
// Remove Customer Attribute
$this->removeAttribute('customer', 'customer_attribute_code');
$this->endSetup();

If you need something more complex like removing groups or attribute sets that can also be done via a script too.

Related Topic