5

Sales -> Orders -> Mass Action Here I want to remove the Print Invoice button from the drop-down.

2 Answers 2

6

You can also use the actionDisable setting in your custom module, that should disable the option in the dropdown:

<massaction name="listing_massaction" component="Magento_Company/js/grid/massactions">
    <action name="enable">
        <settings>
            <actionDisable>true</actionDisable>
        </settings>
    </action>
</massaction>
1
  • This should be the accepted answer May 2, 2023 at 2:04
5

You need to create a simple module to remove Print Invoices action from the sales orders actions drop-down.

I am listing down the main steps. I assume that you already know the about required files to create a Magento 2 module working.

Step 1: Create a file app/code/Stack/RuleBasedDiscount/view/adminhtml/ui_component/sales_order_grid.xml and put the following code:

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <listingToolbar name="listing_top">
        <massaction name="listing_massaction" class="Stack\RuleBasedDiscount\Ui\MassAction">
        </massaction>
    </listingToolbar>
</listing>

Step 2: Create the file app/code/Stack/RuleBasedDiscount/Ui/MassAction.php and put the following code:

<?php
namespace Stack\RuleBasedDiscount\Ui;

class MassAction extends \Magento\Ui\Component\MassAction
{
    private $authorization;
    public function __construct(
            \Magento\Framework\View\Element\UiComponent\ContextInterface $context,
            \Magento\Framework\AuthorizationInterface $authorization,
            array $components,
            array $data
    ) {
        $this->authorization = $authorization;
        parent::__construct($context, $components, $data);
    }

    public function prepare() {
        parent::prepare();
        $config = $this->getConfiguration();
        //if (!$this->authorization->isAllowed('Magento_Catalog::the_acl_youd_like_to_use')) {
        $allowedActions = [];
        foreach ($config['actions'] as $action) {
            if ('pdfinvoices_order' != $action['type']) {
                $allowedActions[] = $action;
            }
        }
        $config['actions'] = $allowedActions;
        //}
        $this->setData('config', (array)$config);
    }
}

Step 3: Run the following commands under document root:

php bin/magento s:up
php bin/magento cache:flush
5
  • @amit-naraniwal, php bin/magento s:up is the shorthand for php bin/magento setup:upgrade Jun 28, 2018 at 13:23
  • Is it working for you? Jun 28, 2018 at 13:26
  • @amitnaraniwal, can you please upvote my answer if it helped? Jun 29, 2018 at 6:36
  • Hello i have tried your all three steps but it nor wokring for me , my code in app/code folder , i am using magento 2.3 Mar 22, 2019 at 7:10
  • Here array needs to be added before "$components" variable in constructor, otherwise it will throw incorrect argument type error in code compilation. Jun 3, 2019 at 10:37

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.