1

I want to remove (or hide) the delete option from the product listing mass action in the Admin section. I cannot find the correct way to do this.

This shows how to hack the core files which is not very useful

This shows you how to add to the ui component

The file Catalog/view/adminhtml/ui_component/product_listing.xml is what I would like to override/edit. I have created the custom module and can add to the ui component but I cannot simply remove the option in Module/ModuleName/view/adminhtml/ui_component/product_listing.xml

So what am I missing? I have tried simply removing the option in the custom module after copying all of the XML over but that obviously did nothing. How do I Customize the options?

   <massaction name="listing_massaction"
                component="Magento_Ui/js/grid/tree-massactions"
                class="\Magento\Catalog\Ui\Component\Product\MassAction">
        <action name="delete">
            <settings>
                <confirm>
                    <message translate="true">Delete selected items?</message>
                    <title translate="true">Delete items</title>
                </confirm>
                <url path="catalog/product/massDelete"/>
                <type>delete</type>
                <label translate="true">Delete</label>
            </settings>
        </action>
        <action name="status">
            <settings>
                <type>status</type>
                <label translate="true">Change status</label>
                <actions>
                    <action name="0">
                        <type>enable</type>
                        <label translate="true">Enable</label>
                        <url path="catalog/product/massStatus">
                            <param name="status">1</param>
                        </url>
                    </action>
                    <action name="1">
                        <type>disable</type>
                        <label translate="true">Disable</label>
                        <url path="catalog/product/massStatus">
                            <param name="status">2</param>
                        </url>
                    </action>
                </actions>
            </settings>
        </action>
        <action name="attributes">
            <settings>
                <url path="catalog/product_action_attribute/edit"/>
                <type>attributes</type>
                <label translate="true">Update attributes</label>
            </settings>
        </action>
    </massaction>

2 Answers 2

3

Try using plugin:

app/code/SR/MagentoCommunity/etc/adminhtml/di.xml

<?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="SR\MagentoCommunity\Plugin\Catalog\Ui\Component\Product\MassAction" sortOrder="1"/>
    </type>
</config>

app/code/SR/MagentoCommunity/Plugin/Catalog/Ui/Component/Product/MassAction.php

<?php
namespace SR\MagentoCommunity\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;
    }
}
2
  • sir can you please help me to solve this issue Jul 25, 2019 at 12:36
  • This worked for me and is the correct way from what I can tell.
    – S-Thomas
    Jul 25, 2019 at 20:09
1

To do this and limit the options to different User Roles I used the answer from @Sohel-Rana and added \Magento\Backend\Model\Auth\Session $adminSession to the code.

Module/Plugins/etc/di.xml

<?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="module_plugins_magento_catalog_ui_component_product_massaction" type="Module\Plugins\Plugin\Magento\Catalog\Ui\Component\Product\MassAction"/>
</type>

Module/Plugins/Plugin/Magento/Catalog/Ui/Component/Product/MassAction.php

namespace Module\Plugins\Plugin\Magento\Catalog\Ui\Component\Product;

class MassAction
{
    public function __construct(  \Magento\Backend\Model\Auth\Session $adminSession)
    {
        $this->_adminSession = $adminSession;
    }

    public function afterIsActionAllowed(

        \Magento\Catalog\Ui\Component\Product\MassAction $subject,
        $isAllowed,
        $actionType
    ) {
        $roleData = $this->_adminSession->getUser()->getRole()->getData();

        if ($actionType == 'delete' && trim($roleData['role_name'])=='Content-Manager') {
            return false;
        }

        return $isAllowed;
    }
}
1
  • Thanks for the solution for specific User Roles. Feb 14, 2020 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.