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

Posted: August 28, 2009 in Magento, Version 1.3.*

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…

-Bijal Bhavsar 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s