How To

How to Remove “Delete” Mass Action from Product Grid Programmatically in Magento 2?

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!

Click to rate this post!
[Total: 4 Average: 3]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide

Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…

16 hours ago

Enhancing Web Application Security with Laravel’s Built-In Features

In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…

2 days ago

Magento 2 Extensions Digest October 2024 (New Release & Updates)

October was an exciting month for MageComp! From significant updates across our Magento 2 extension…

2 days ago

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

1 week ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

2 weeks ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

2 weeks ago