Hello Magento Friends,
The current tutorial is about removing the “delete” mass action from the admin product grid in Magento 2. We will be performing the steps programmatically. Before starting let’s understand about delete action.
Magento 2 admin grid allows managing products and applying various bulk actions on them. One of the mass actions is “delete”. Look at the below image
Admin users can delete multiple products at a time. But if you want to remove the “Delete” option from the mass action for admin users, you can achieve it programmatically in Magento 2.
Steps to Remove “Delete” Mass Action from Product Grid Programmatically in Magento 2:
Step 1: We need to create a “di.xml” file inside our extension at the following path
app\code\Vendor\Extension\etc\adminhtml\
Then add the following code
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Ui\Component\Product\MassAction"> <plugin name="hide_delete_from_catalog_massaction" type="Vendor\Extension\Plugin\Catalog\Ui\Component\Product\MassAction" sortOrder="1"/> </type> </config>
Step 2: After that, we need to create a “MassAction.php” file inside our extension at the following path
app\code\Vendor\Extension\Plugin\Catalog\Ui\Component\Product\
Then add the code mentioned below
<?php namespace Vendor\Extension\Plugin\Catalog\Ui\Component\Product; class MassAction { public function afterIsActionAllowed( \Magento\Catalog\Ui\Component\Product\MassAction $subject, $isAllowed, $actionType) { if ($actionType == 'delete') { return false; } return $isAllowed; } }
Result:
Check your Magento 2 product grid from the admin panel. You can see the “delete” option has been removed from the mass actions.
Conclusion:
This way you can successfully erase the “delete” action from the admin product grid in Magento 2. In case you are unable to achieve the desired result, get in touch with me through the comment box. I will be happy to help you.
You can also add a custom mass action to the product grid in Magento 2. Also, track all the activities performed by your admin users by installing Magento 2 Admin Action Log.
Share the article with your friends and stay updated with the latest articles.
Happy Coding!