skip to Main Content

In Sales->Invoice->Invoice Grid, I added a column Payment method.

In the $collection, I joined the sales_flat_order_payment table so I can pull the method of each entity_id and did it successfully. When I echo the query and use it in Mysql, it returns the results I wanted.

Now, I want the method column of mysql be visible in Invoice Grid.

Here’s what I did.

I followed some steps in here.
Add custom renderer for a custom column in Magento grid

Now here’s my code.

In my

app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Grid.php

Here’s my $collection

$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join( array('a'=> mgmx_sales_flat_order_payment), 'a.entity_id = main_table.entity_id', array('a.method'));
$this->setCollection($collection);
/*echo $collection->getSelect();die();*/
return parent::_prepareCollection();

Then in _prepareColumns

$this->addColumn('payment_mode', array(
        'header'    => Mage::helper('sales')->__('Payment Mode'),
        'index'     => 'method',
        'renderer'  => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Red',
    ));

Then I create a Renderer Directoy and a Red.php inside the Renderer Directory

app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Renderer

<?php 
class Mage_Adminhtml_Block_Catalog_Product_Renderer_Red extends 
  Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { 
  public function render(Varien_Object $row) { 
    $value =  $row->getData($this->getColumn()->getIndex());
  return $value;
 }
}
?>

But this one returns an error

Fatal error: Call to a member function setColumn() on boolean in /home/xxxxxxx/xxxx.xxxxxx.com/xxxxx/includes/src/Mage_Adminhtml_Block_Widget_Grid_Column.php on line 291

2

Answers


  1. Why do you need a custom renderer when adding a new column?

    just leave out the renderer, if you don’t need any custom output:

    $this->addColumn('payment_mode', array(
            'header'    => Mage::helper('sales')->__('Payment Mode'),
            'index'     => 'method',
        ));
    
    Login or Signup to reply.
  2. To fix your example you will have to change the namespace of your renderer

    your class path is

    app/code/core/Mage/Adminhtml/Block/Sales/Invoice/Renderer
    

    but your class name is

    Mage_Adminhtml_Block_Catalog_Product_Renderer_Red
    

    this can never work with magento autoload. you will have to put your class into:

    app/code/core/Mage/Adminhtml/Block/Catalog/Product/Renderer
    

    (or completely change the class name, whatever you may prefer)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search