Magento Coding Solutions

how To add Custom Tab in admin Cetalog Product programmatically


We  want to add New Tab "Manage Weight" to manage My custom Code
1)Create a module "example NameSpace: Jewelry and Module Name: Basicprice "
2) Do Change in Module
                i)  in config.xml
                                <global>
                                                <blocks>
                                                                 <basicprice>
                                                                                <class>Jewelry_Basicprice_Block</class>
                                                                  </basicprice>                                                  
                                                </blocks>
                                </global>
replace  this code to overwrite product TAB
Code is:
<global>
<blocks> <basicprice><class>Jewelry_Basicprice_Block</class>  </basicprice>  
<adminhtml> <rewrite>                                                                                                   <catalog_product_edit_tabs>Jewelry_Basicprice_Block_Adminhtml_Tabs</catalog_product_edit_tabs></rewrite></adminhtml></blocks>
</global>
ii) Make a file "Tabs.php" in location app/code/local/Company/ModuleName/Block/Adminhtml/tabs.php
and past this code
<?php
class Jewelry_Basicprice_Block_Adminhtml_Tabs extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs
{    public $parent;
    protected function _prepareLayout()    {
        //get all existing tabs
        $this->parent = parent::_prepareLayout();
        //add new tab
        $this->addTab('tabid', array(
            'label'     => Mage::helper('catalog')->__(' Manage Weight'),
            'content'   => $this->getLayout()->createBlock('basicprice/adminhtml_tabs_tabid')->toHtml(),

        ));
        return $this->parent;
    }
}?>

/public_html/app/code/local/Company/ModuleName/Block/Adminhtml/tabs.php
iii)Make a folder "Tabs" in location  app/code/local/Company/ModuleName/Block/Adminhtml/tabs/
iv) Create a "Tabid.php" file in location app/code/local/Company/ModuleName/Block/Adminhtml/tabs/ Tabid.php
and past this code
<?php
class Jewelry_Basicprice_Block_Adminhtml_Tabs_Tabid extends Mage_Adminhtml_Block_Widget
{    public function __construct()
    {        parent::__construct();
        $this->setTemplate('weight.phtml');
    }
}
?>

v) create a file weight.phtml in location  "app/design/adminhtml/default/default/template/ weight.phtml "
to manage Your custom code
Example:



Make custom url in Magento Modul in Admin


<?php
My actual Url is
"http://localhost/magento/index.php/admin_metal/adminhtml_metalbackend/index/key/f64c498b4c19e35795ce97188cd3c3ee/";

we create Url by Pragmatically :
echo Mage::helper("adminhtml")->getUrl("metal/adminhtml_metalbackend");

?>

Remove Or Rename “Add New ” Button From Admin Grid In Magento Module

Example: "Jewelry" is my  Namespace and  "Basicprice" is my Module

Rename ‘Add New’ Button:

Step 1 : Go to app\code\local\Jewelry\Basicprice\Block\Adminhtml\Basicprice.php

There is a code 
public function __construct()
{

$this->_controller = "adminhtml_basicprice";
$this->_blockGroup = "basicprice";
$this->_headerText = Mage::helper("basicprice")->__("Basicprice Manager");
$this->_addButtonLabel = Mage::helper("basicprice")->__("Add New Item");
parent::__construct();


}


Step 2 : replace  $this->_addButtonLabel = Mage::helper("basicprice")->__("Add New Item");  to $this->_addButtonLabel = Mage::helper("basicprice")->__("Your Custom Name");


Here are the steps to remove the “Add New” button

Step 1 :  Go to app\code\local\Jewelry\Basicprice\Block\Adminhtml\Basicprice.php
and add  this code "$this->_removeButton('add'); " in below parent::__construct(); function

Example:
public function __construct()
{

$this->_controller = "adminhtml_basicprice";
$this->_blockGroup = "basicprice";
$this->_headerText = Mage::helper("basicprice")->__("Basicprice Manager");
$this->_addButtonLabel = Mage::helper("basicprice")->__("Add New Item");
parent::__construct();
$this->_removeButton('add');

}