我已经阅读了几篇关于堆栈溢出的帖子
和magento论坛上的几个线程
但是,这些帖子都没有尝试做我想做的事情
我想覆盖
app/design/adminhtml/default/default/template/widget/grid.phtml
文件,因为该文件包含 html 的一部分,允许任何人从 sales->order View 导出。
注意:我们在权限->角色 View 中禁用了此用户角色的所有导出选项
显示“导出到:”->“CSV/Excel XML”功能的代码包含在我上面列出的路径中。我想删除那 block html 并覆盖 Magento 包含的文件。
最佳答案
Adminhtml 使用与前端相同的主题回退,因此您只需在模块配置 XML 中为您的安装声明一个自定义模板主题:
<stores>
<admin>
<design>
<theme>
<template>custom</template>
</theme>
</design>
</admin>
</stores>
然后您可以使用您喜欢的任何自定义创建 app/design/adminhtml/default/custom/template/widget/grid.phtml,该文件将优先使用 中的文件。默认/默认 adminhtml 主题。然后,您的解决方案是在呈现导出控制的逻辑中添加 ACL 检查:
<?php if($this->getExportTypes() && {ACL LOGIC}}): ?>
<td class="export a-right">
<img src="<?php echo $this->getSkinUrl('images/icon_export.gif') ?>" alt="" class="v-middle"/> <?php echo $this->__('Export to:') ?>
<select name="<?php echo $this->getId() ?>_export" id="<?php echo $this->getId() ?>_export" style="width:8em;">
<?php foreach ($this->getExportTypes() as $_type): ?>
<option value="<?php echo $_type->getUrl() ?>"><?php echo $_type->getLabel() ?></option>
<?php endforeach; ?>
</select>
<?php echo $this->getExportButtonHtml() ?>
</td>
<?php endif; ?>
虽然这个逻辑在 block 类中可能更合适地实现,但类重写系统不适应父类的重写,让您重写每个子类。在这种情况下,遵守 DRY 胜过在模板中嵌入太多逻辑。此外,这种变化是显而易见的并且易于维护。
理想情况下,核心团队会在
Mage_Adminhtml_Block_Widget_Grid
中实现此检查。类或至少为 _exportTypes
提供了一个公共(public) setter 属性,这将使该逻辑更易于实现。
关于Magento - 覆盖 adminhtml 模板文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14448983/