Just another WordPress.com weblog

Archive for August, 2009

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

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

How to add new tab in left panel, when add new product in admin panel?

For Above subject,

1. ) First create Newtab.php

app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab

content of this file looks something like this

<?php

class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Newtab extends Mage_Adminhtml_Block_Widget_Form {
public function __construct()
{
parent::__construct();
$this->setTemplate(‘catalog/product/edit/tab/newtab.phtml’);
}

protected function _prepareLayout()
{

return parent::_prepareLayout();
}

public function initForm(){

$form = new Varien_Data_Form();
return $this;
}

}
?>

2 ) Create a file newtab.phtml
/var/www/magento/app/design/adminhtml/default/default/template/catalog/product/tab

content of this file is

<div>

New Tab File Content

</div>

3) the important step is adding the tab

app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab.php

$this->addTab(’addresses’, array(
‘label’ => Mage::helper(’customer’)->__(’New Tab’)
, ‘content’ => $this->getLayout()->createBlock(’adminhtml/customer_edit_tab_newtab’)->initForm()->toHtml(),
));

– Jinesh Soni