Skip to main content

Removing delete mass action from product grid

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· One min read
Stephan Hochdörfer
Head of IT Business Operations

One of our customers asked us to remove the delete option from the mass action element for the product grid. What sounded like a simple task evolved into a lot of debugging and testing. Apparently removing the mass action option from the xml configuration does not work even though a lot of StackOverflow posts say so. The only way that worked for me, was to do it programmatically like this:

Extend the default Product Grid, overwrite the _prepareMassaction() method and remove the delete option there:

<?php

namespace Vendor\Product\Block\Adminhtml\Product;

class Grid extends \Magento\Catalog\Block\Adminhtml\Product\Grid
{
protected function _prepareMassaction()
{
parent::_prepareMassaction();
$this->getMassactionBlock()->removeItem('delete');
}
}

After that the DI configuration needs to modified as well, making sure Magento will use our implementation instead of the default one:

<?xml version="1.0"?>
<config xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/
etc/config.xsd">

<preference for="Magento\Catalog\Block\Adminhtml\Product\Grid"
type="Vendor\Product\Block\Adminhtml\Product\Grid"/>
</config>