I want to remove the "Delete" mass action from the Products grid. I am trying to do this from my observer. Here is my observer class
class NameSpace_Module_Model_Observer {
public function isAddProductDeletePermitted($observer) {
$block = $observer->getBlock();
if( $block !== null ) {
if( $block instanceof Mage_Adminhtml_Block_Cms_Block_Grid) {
$block->getMassactionBlock()->removeItem('delete');
// echo "DELETE";
}
}
return $this;
}
And here is my config.xml
<?xml version="1.0"?>
<config>
. . .
<global>
. . .
<events>
<adminhtml_block_html_before>
<observers>
<is_add_product_form_permitted>
<class>Dotlocal_AdvProductGrid_Model_Observer</class>
<method>isAddProductDeletePermitted</method>
</is_add_product_form_permitted>
</observers>
</adminhtml_block_html_before>
</events>
</global>
</config>
I cannot seem to get this to work. I am pretty sure this doesn't work because I am trying to removing it before it is added. Then what event should I be observing?
Best Answer
You have an error in your Observer class because
Mage_Adminhtml_Block_Cms_Block_Grid
should beMage_Adminhtml_Block_Catalog_Product_Grid
However you are also right that there is a better event to use, you can use
'adminhtml_catalog_product_grid_prepare_massaction'
so you can do the same code but without the instanceof check and that will do what you need.That said... I obviously don't know why you want to do this but I imagine if I was doing it it's because I don't want person X to accidentally remove a bunch of products. And so you could go a little futher and remove this action on a user basis by adding it as a acl configuration and checking if that user is allowed in the observer as per below.
etc/adminhtml.xml
Model/Observer.php