1

我试图覆盖块 Mage_Adminhtml_Block_Catalog_Product_Edit 并以这种方式创建按钮“delete_cache_product”:

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;
}

问题是如何为该按钮关联资源acl,以便只有有权访问此类资源的用户才能看到该按钮???

4

2 回答 2

2

然后使用 ACL 创建一个自定义管理模块

 if(Mage::getSingleton('admin/session')->isAllowed('admin/custommodulename')){
    $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?')
        ))
    );
 }

请参阅http://alanstorm.com/magento_acl_authentication

于 2013-02-19T17:38:54.587 回答
1

我终于找到了解决方案。:我在其中创建了一个权限,adminhtml.xml然后直接调用:

# 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')) {
    ...
}
于 2013-02-20T16:53:22.380 回答