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.