4

I want to remove the following from sale order grid:

  • New Order RSS
  • Export to:
  • MassAction block

for a particular admin user role.

I currently use adminhtml_block_html_before event to remove the MassAction block:

my observer method:

    public function salesOrderVendorLayout($evt){
        $tabBlock = $evt->getBlock();
        if($tabBlock instanceof Mage_Adminhtml_Block_Sales_Order_Grid){
            $tabBlock->setMassactionIdField('');
        }
    }

enter image description here

My Questions:

  1. Is this the right way to remove mass action block?
  2. How can I remove the remaining two blocks?

3 Answers 3

6

I don't think there is a way to remove the rss link and the export types through an observer.
For example, the code that shows the export types is this:

<?php if($this->getExportTypes()): ?>
    <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; ?>

The only way to make it not appear is to make getExportTypes return null or false and the method looks like this:

public function getExportTypes()
{
    return empty($this->_exportTypes) ? false : $this->_exportTypes;
}

_exportTypes is protected and the only public methods that access it are getExportTypes for retrieving and addExportType for adding a new export type. There is no way to remove them. The same goes for RSS lists.
Here is what I would do in your case. I would rewrite the orders grid block Mage_Adminhtml_Block_Sales_Order_Grid and add the following methods:

public function getExportTypes(){
    return false;
}
public function getRssLists(){
    return false;
}
protected function _prepareMassaction(){
    return $this;
}

Even better, I would implement a way to still be able to show them by changing a config setting in the backend (if needed).

public function getExportTypes(){
    if (!Mage::getStoreConfigFlag('some/config/path')){ //if some flag is not set let it behave as default.
        return parent::getExportTypes();
    }
    return false;
}
4

I see three ways:

The easy one: CSS

Just add a new css file and hide everything you want

Change the template

There is a standard template which is used for every grid and its container:

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

Just change the template in your own layout.xml file, copy the template and remove the parts you don't want

Rewrite the block

Rewrite the block \Mage_Adminhtml_Block_Catalog_Product_Grid and change the method \Mage_Adminhtml_Block_Catalog_Product_Grid::_prepareMassaction to do nothing

3

Here is what I did:

class Mynamespace_Mymodule_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid{

    protected $_idArray = array();

    public function __construct()
    {
        parent::__construct();
        $this->_idArray = Mage::helper('mymodule')->getUserInfo();
    }

    public function getExportTypes(){
        if($this->_idArray['user_role'] == 'xyz'){
            return false;
        } else{
            return $this->_exportTypes;
        }
    }

    public function getRssLists(){
        if($this->_idArray['user_role'] == 'xyz'){
            return false;
        } else{
            return $this->_rssLists;
        }
    }

    protected function _prepareMassaction(){
        if($this->_idArray['user_role'] == 'xyz'){
            return $this;
        } else{
            parent::_prepareMassaction();
        }
    }

}

where getUserInfo() is my helper class method which will get the user id and user role from admin/session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.