PHP Magento Tips

Add Product Edit Link In Category Product Tab in Magento Admin With Custom Renderer

Rate this posting:
{[['']]}

To Add Product Edit Link In Category Product Tab in Magento Follow Below Steps:

Step 1: add below code in  app/etc/modules/Mycompany_CategoryProductlink.xml

<?xml version="1.0"?>

<config>

    <modules>

        <Mycompany_CategoryProductlink>

            <active>true</active>

            <codePool>local</codePool>

        </Mycompany_CategoryProductlink>

    </modules>

</config>

Step 2: Create config.xml file. Add below code in app/code/local/Mycompany/CategoryProductlink/etc/config.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Mycompany_CategoryProductlink>
            <version>0.1.1</version>
        </Mycompany_CategoryProductlink>
    </modules>
 <global>
        <blocks>
         <categoryproductlink>
          <class>Mycompany_CategoryProductlink_Block</class>
     </categoryproductlink>
    <adminhtml>
     <rewrite>
      <catalog_category_tab_product>Mycompany_CategoryProductlink_Block_Adminhtml_Catalog_Category_Tab_Product</catalog_category_tab_product>
     </rewrite>    
    </adminhtml>                   
        </blocks>   
        <helpers>
         <categoryproductlink>
          <class>Mycompany_CategoryProductlink_Helper</class>          
         </categoryproductlink>
        </helpers> 
        <resources>
            <categoryproductlink_setup>
                <setup>
                    <module>Mycompany_CategoryProductlink</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </categoryproductlink_setup>
            <categoryproductlink_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </categoryproductlink_write>
            <categoryproductlink_read>
                <connection> 
                    <use>core_read</use>
                </connection>
            </categoryproductlink_read>
       </resources>          
  </global>
</config>

Here we rewrite catalog_category_tab_product block and called our own block.

Step 3: Create our own block file and below code.

Create app/code/local/Mycompany/CategoryProductlink/Block/Adminhtml/Catalog/Category/Tab/Product.php and add below code:

<?php

class Mycompany_CategoryProductlink_Block_Adminhtml_Catalog_Category_Tab_Product extends Mage_Adminhtml_Block_Catalog_Category_Tab_Product {

 protected function _prepareColumns()
 {
  parent::_prepareColumns();
  $this->addColumn('edit', array(
    'header'    => Mage::helper('catalog')->__('Action'),
    'width'     => '80',
    'filter'  =>false,
    'sortable'  => false,
    'index' =>'entity_id',
    'renderer'  => 'categoryproductlink/renderer_category_productlink'
  ));

 }
}

Here in addColumn method we passed renderer parameter to extend Category product grid.

Step 4: Now create a file in app/code/local/Mycompany/CategoryProductlink/Block/Renderer/Category/Productlink.php and add below code:

<?php

class Mycompany_CategoryProductlink_Block_Renderer_Category_Productlink extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
 
 public function render(Varien_Object $row)
 {
  $value = $row->getData($this->getColumn()->getIndex());    
   $url=Mage::getUrl('*/catalog_product/edit', array('id' =>$value, '_secure'=>true, '_current' => true, '_store'=>Mage::app()->getRequest()->getParam('store')));  
  $value='<a href="'.$url.'" target="_blank" >Edit</a>';
  return $value;
 }
}

Now Create Helper data file. Create a file in app/code/local/Mycompany/CategoryProductlink/Helper/Data.php and add below code in it:

<?php

class Mycompany_CategoryProductlink_Helper_Data extends Mage_Core_Helper_Abstract
{
  
}

Now refresh your cache from backend and check catalog >> Manage Categories. You will find Edit Product link at last.


Download Whole Module From Github: https://github.com/vijayrami/Category_Productlink_renderer
Tag : Magento
1 Comments On "Add Product Edit Link In Category Product Tab in Magento Admin With Custom Renderer"

Great blog. All posts have something to learn. Your work is very good and i appreciate you and hoping for some more informative posts.keep writing
magento development company in bangalore 

Back To Top