To hide or change “Add New” or “Add Item” button from Admin module.

0
18
views
Advertisement

We can give condition to hide or change “Add New” or “Add Item” button from Admin module. We can give any condition also .. but for these we must know that in which file we have to give condition to hide “Add New” button.

projectname/app/code/core/mage/adminhtml/block/widget/grid/container.php
In the above file we have to change in one function :

public function __construct()
{
parent::__construct();

$this->setTemplate(‘widget/grid/container.phtml’);

$this->_addButton(‘add’, array(
‘label’ => $this->getAddButtonLabel(),
‘onclick’ => ‘setLocation(” . $this->getCreateUrl() .”)’,
‘class’ => ‘add’,
));
}

You can see the changes done in below function::
public function __construct()
{
parent::__construct();

$this->setTemplate(‘widget/grid/container.phtml’);
/****************Condition Added to hide Add item button from requestproduct and rightbanner modules *******************/
$flag = false;
$path = $this->getRequest()->getPathInfo();
$pathinfo = explode(‘/’,$path);

if(sizeof($pathinfo) > 0){
if(in_array(‘requestproduct’,$pathinfo)){
$flag = true;
}

if(in_array(‘rightbanner’,$pathinfo)){
$resource = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$sql = “SELECT * FROM `rightbanner`”;
$collection = $resource->fetchAll($sql);
if(sizeof($collection) > 0)$flag = true;
}
}
if(!$flag){
$this->_addButton(‘add’, array(
‘label’ => $this->getAddButtonLabel(),
‘onclick’ => ‘setLocation(” . $this->getCreateUrl() .”)’,
‘class’ => ‘add’,
));
}
/****************END*****************/
}

If this is helpful to you than please do right comment…

-Mayank Zalavadia