Search code examples
magentobuttonadminaclproduct

Magento : add a button to the edit product page accessible to a specific resource acl


I tried to override the block Mage_Adminhtml_Block_Catalog_Product_Edit and I create the button "delete_cache_product" this way:

protected function _prepareLayout()
{
    parent::_prepareLayout();
        $this->_product = $this->getProduct();
        $this->setChild('delete_cache_product',
            $this->getLayout()->createBlock('adminhtml/widget_button')
                ->setData(array(
                'label'     => Mage::helper('catalog')->__('delete cache'),
                'onclick'   => 'confirmSetLocation(\''.Mage::helper('catalog')->__('Are you sure?').'\', \''.$this->getDeleteCacheProductUrl().'\')',
                'title' => Mage::helper('catalog')->__('Delete product cache?')
            ))
        );
    return $this;
}

the problem is how can I associate a resource acl for that button so that only users who have access to such resources can see the button???


Solution

  • I finally found the solutio.: I create a permission in adminhtml.xml and I call directly:

    # File: adminhtml.xml
    <config>
        <acl>
            <admin>
                <children>
                    <catalog>
                        <children>
                            <products>
                                <children>
                                    <deletecacheproduct>
                                        <title>Delete product cache</title>
                                        <sort_order>0</sort_order>
                                    </deletecacheproduct>
                                </children>
                            </products>
                        </children>
                    </catalog>
                </children>
                </admin>
            </resources>
        </acl>
    </config>
    

    # File: Edit.php (block)
    
    if (Mage::getSingleton('admin/session')->isAllowed('catalog/products/deletecacheproduct')) {
        ...
    }