Magento – Remove product delete button from admin

adminadminhtmlproducts-management

Is there a way to remove the delete button from the manage products backend? I understand that this would make it impossible to remove products. Preferably, it would not require a change to the core.

Best Answer

If you are worried of people accidentally clicking the delete button you can take the simple approach @Prashanta suggested. Hiding it via css. It should work.
If you want to completely remove the delete button and the delete action you need to rewrite the product edit block and the product admin controller. You also need to remove the mass action delete from the grid.
For this you will need a custom extension. Let's call it StackExchange_Catalog.
You will need the following files.

app/etc/modules/StackExchange_Catalog.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Catalog>
            <codePool>local</codePool>
            <active>true</active>
            <depends>
                <Mage_Catalog />
                <Mage_Adminhtml />
            </depends>
        </StackExchange_Catalog>
    </modules>
</config>

app/code/local/StackExchange/Catalog/etc/config.xml - the configuration file

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Catalog>
            <version>1.0.0</version>
        </StackExchange_Catalog>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <catalog_product_edit>StackExchange_Catalog_Block_Adminhtml_Product_Edit</catalog_product_edit><!-- remove the delete button -->
                    <catalog_product_grid>StackExchange_Catalog_Block_Adminhtml_Product_Grid</catalog_product_grid><!-- remove the mass action delete -->
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules><!-- disallow delete actions -->
                        <StackExchange_Catalog before="Mage_Adminhtml">StackExchange_Catalog_Adminhtml</StackExchange_Catalog>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

app/code/local/StackExchange/Catalog/Block/Adminhtml/Product/Edit.php - your version of the product edit block

<?php
class StackExchange_Catalog_Block_Adminhtml_Product_Edit extends Mage_Adminhtml_Block_Catalog_Product_Edit
{
    /**
     * no delete button for you
     * @return string
     */
    public function getDeleteButtonHtml()
    {
        return '';
    }
}

/app/code/local/StackExchange/Catalog/Block/Adminhtml/Product/Grid.php - your grid version that removes the mass action delete.

<?php
class StackExchange_Catalog_Block_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
    protected function _prepareMassaction()
    {
        parent::_prepareMassaction();
        $this->getMassactionBlock()->removeItem('delete');
        return $this;
    }
}

app/code/local/StackExchange/Catalog/controllers/Adminhtml/Catalog/ProductController.php - your new product controller that disables the delete action just in case someone guesses the delete URL. This should never happen but let's be paranoid.

<?php
require_once 'Mage/Adminhtml/controllers/Catalog/ProductController.php';
class StackExchange_Catalog_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
    /**
     * just redirect to index on the delete action
     */
    public function deleteAction()
    {
        $this->_getSession()->addWarning($this->__('Product deletion is prohibited'));
        $this->_redirect('*/*/index');
    }

    /**
     * don't allow mass delete either
     */
    public function massDeleteAction()
    {
        $this->_getSession()->addWarning($this->__('Product deletion is prohibited'));
        $this->_redirect('*/*/index');
    }
}