0

I am trying to observe this event:

Event Name : adminhtml_catalog_product_grid_prepare_massaction

Defined in : \vendor\magento\module-catalog\Block\Adminhtml\Product\Grid.php

$this->_eventManager->dispatch('adminhtml_catalog_product_grid_prepare_massaction', ['block' => $this]);

Here is my events.xml

app\code\Mypackage\Massproductaction\etc\adminhtml\events.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="adminhtml_catalog_product_grid_prepare_massaction">
        <observer instance="Mypackage\Massproductaction\Observer\Addmassactions" name="custom_add_massaction"/>
    </event>
</config>

Here is my observer

app\code\Mypackage\Massproductaction\Observer\Addmassactions.php

<?php
namespace Mypackage\Massproductaction\Observer;

class Addmassactions implements \Magento\Framework\Event\ObserverInterface
{

    protected $scopeConfig;
    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    ) {
        $this->scopeConfig = $scopeConfig;
    }

    /**
     * Execute observer
     *
     * @param \Magento\Framework\Event\Observer $observer
     * @return void
     */
    public function execute(
        \Magento\Framework\Event\Observer $observer
    ) {
        exit("Should come here.");
    }
}

Few of other events are working fine.

As it is defined, why it is not working? I want to add some dynamic mass-actions based on Settings (Configurations), so in this observer I will check the settings and will add to mass action to admin product grid.

I know it can be done with ui_component >> product_listing.xml

But as I told, I need it condition based.

Please help. Thanks in advance.

1

I'm pretty sure this is because the catalog product grid is using UI Components and not using the old Grid block anymore.

This event is only triggered for grid blocks such as the newsletter subscriber grid (in 2.1.2).

The plan is, in the future, to have all admin grids and forms (as well as frontend ones) using UI Components so this event will pretty much be useless/deprecated AFAIK.

  • Any other way to have condition based ui component? – Kapil Karangeeya Dec 5 '16 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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