---
title: "Magento 2: How to Add Custom Mass Action in Product Grid"
url: "https://magecomp.com/blog/magento-2-add-custom-mass-action-in-product-grid/"
date: "2020-11-16T10:00:20+00:00"
modified: "2025-02-20T06:58:08+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 636
reading_time: "4 min read"
summary: "Hello Magento Friends ?,"
description: "Magento 2 provides mass actions for the product grid. But if you need to add your custom mass action to the product grid, follow the steps."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to assign guest customers orders into registered account in Magento 2?"
    url: "https://magecomp.com/blog/assign-guest-customers-orders-into-registered-account-in-magento-2/"
  - title: "Top 5 Magento Development Tools You&#8217;ll Need to Thrive in 2026"
    url: "https://magecomp.com/blog/top-magento-development-tools/"
  - title: "How to Get Child Items of Bundle Products in Magento 2"
    url: "https://magecomp.com/blog/get-child-items-of-bundle-products-magento-2/"
---

# Magento 2: How to Add Custom Mass Action in Product Grid

_Published: November 16, 2020_  
_Author: Dhiren Vasoya_  

![How-to-Add-Custom-Mass-Action-in-Product-Grid-in-m2](https://magecomp.com/blog/wp-content/uploads/2020/11/How-to-Add-Custom-Mass-Action-in-Product-Grid-in-m2-1024x512.webp)

**Hello Magento Friends ?,**

In this article, I am going to explain Magento 2: How to Add Custom Mass Action in Product Grid. Look at our previously published blog, [**Magento 2: How to Redirect on Checkout Page After Add to Cart**](https://magecomp.com/blog/magento-2-redirect-on-checkout-page-after-add-to-cart/).
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-1.webp)](https://magecomp.com/services/hyva-theme-development/)

Magento 2 comes with UI components that allow adding columns, filters, and mass actions. In Magento 2 there are some mass actions available in the product admin grid. You need to extend the product_listing.xml file, to add custom mass action in the product grid as shown below. By this, custom mass action will be displayed in the dropdown of Action.
Let’s start with the steps to Add Custom Mass Action in the Product grid in Magento 2 ?
## Steps to Add Custom Mass Action in Product Grid in Magento 2:
**Step 1:** Go to the following path:
**app\code\Vendor\Extension\view\adminhtml\ui_component\product_listing.xml**

And add the below code:
```
<?xml version="1.0" encoding="UTF-8"?>
            <massaction name="listing_massaction">
            <action name="is_sale_products">
                <settings>
                    <type>is_sale_products</type>
                    <label translate="true">Is Salable Product</label>
                    <actions>
                        <action name="0">
                            <type>enabled</type>
                            <label translate="true">Enable</label>
                            <url path="extension/index/massSalable">
                                <param name="issalable">1</param>
                            </url>
                        </action>
                        <action name="1">
                            <type>disable</type>
                            <label translate="true">Disable</label>
                            <url path="extension/index/massSalable">
                                <param name="issalable">0</param>
                            </url>
                        </action>
                    </actions>
                </settings>
            </action>
        </massaction>
    ```

**Step 2:** After that, create **MassSalable.php** file at the below path:
**app\code\Vendor\Extension\Controller\Adminhtml\Index\MassSalable.php**

Finally, add the code as mentioned underneath:
```
<?php

namespace VendorExtensionControllerAdminhtmlIndex;

use MagentoBackendAppAction;
use MagentoBackendAppActionContext;
use MagentoFrameworkControllerResultFactory;
use MagentoUiComponentMassActionFilter;
use MagentoCatalogModelResourceModelProductCollectionFactory;

class MassSalable extends Action
{

    /**
     * @var Filter
     */
    protected $filter;

    /**
     * @var CollectionFactory
     */
    protected $prodCollFactory;

    /**
     * @var MagentoCatalogApiProductRepositoryInterface
     */
    protected $productRepository;

    /**
     * @param Context                                         $context
     * @param Filter                                          $filter
     * @param CollectionFactory                               $prodCollFactory
     * @param MagentoCatalogApiProductRepositoryInterface $productRepository
     */
    public function __construct(
        Context $context,
        Filter $filter,
        CollectionFactory $prodCollFactory,
        MagentoCatalogApiProductRepositoryInterface $productRepository)
    {
        $this->filter = $filter;
        $this->prodCollFactory = $prodCollFactory;
        $this->productRepository = $productRepository;
        parent::__construct($context);
    }

    /**
     * Execute action
     *
     * @return MagentoBackendModelViewResultRedirect
     * @throws MagentoFrameworkExceptionLocalizedException | Exception
     */
    public function execute()
    {
        $salableValue = $this->getRequest()->getParam('issalable');
        $collection = $this->filter->getCollection($this->prodCollFactory->create());
        foreach ($collection->getAllIds() as $productId)
        {
            $productDataObject = $this->productRepository->getById($productId);
            $productDataObject->setData('is_sale',$salableValue);
            $this->productRepository->save($productDataObject);
        }
        $this->messageManager->addSuccess(__('A total of %1 record(s) have been modified.', $collection->getSize()));
        /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        return $resultRedirect->setPath('catalog/product/index');
    }
}
```

[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-2.webp)](https://magecomp.com/services/hire-magento-programmer/)

**Output:** In this way, you can set value enable/disable of “Sale” attribute value in the product grid and will get the result as shown in the below image.
![custom mass action](https://magecomp.com/blog/wp-content/uploads/2020/11/custom-mass-action.png)

## Conclusion:
Accordingly, you can add custom mass action in the product grid in Magento 2. As per your requirement, you can add any custom mass action. Similarly, you can even [**Add Custom Mass Action to the Admin Grid in Magento 2**](https://magecomp.com/blog/add-mass-actions-in-magento-2-admin-grid/).
For any doubts and questions, kindly mention in the comment part. Keep sharing and stay connected!
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Happy Coding ?**


---

_View the original post at: [https://magecomp.com/blog/magento-2-add-custom-mass-action-in-product-grid/](https://magecomp.com/blog/magento-2-add-custom-mass-action-in-product-grid/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-25 05:06:47 UTC_  
