Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - Override adminhtml template file

I have read several posts on stack overflow

  • Overriding a Magento Adminhtml template file
  • Magento - overriding Adminhtml block

and a couple threads on the magento forum

  • http://www.magentocommerce.com/boards/viewthread/21978/

However, None of these posts attempt to do what I am trying to do

I would like to override the

app/design/adminhtml/default/default/template/widget/grid.phtml 

file, as this file contains a portion of html that allows anyone to export from the sales->order view.

Note: We have disabled all of the export options for this user role in the permissions->role view

The code that displays the "Export to: " -> "CSV/Excel XML" feature is included in the path I have listed above. I would like to remove that chunk of html and override the file included with Magento.

like image 587
Jeffrey L. Roberts Avatar asked Jan 21 '13 23:01

Jeffrey L. Roberts


1 Answers

Adminhtml uses the same theming fallback as the frontend, therefore you need only declare a custom template theme for your installation in module config XML:

<stores>
    <admin>
        <design>
            <theme>
                <template>custom</template>
            </theme>
        </design>
    </admin>
</stores>

Then you can create app/design/adminhtml/default/custom/template/widget/grid.phtml with any customizations you like, and this file will be used in preference to the one from the default/default adminhtml theme. Your solution then would be to add an ACL check in the logic which renders the export control:

<?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"/>&nbsp; <?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; ?>

While this logic might be more appropriately implemented in the block class, the class rewrite system does not accommodate rewriting of parent classes, leaving you to rewrite every subclass. In this instance, obeying DRY outweighs embedding too much logic in templates. Moreover, the change is obvious and easily maintained.

Ideally the core team would have implemented this check in the Mage_Adminhtml_Block_Widget_Grid class or at least provided a public setter for the _exportTypes property, which would have made this logic a bit cleaner to implement.

like image 164
benmarks Avatar answered Oct 19 '22 20:10

benmarks