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
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:
To fix your example you will have to change the namespace of your renderer
your class path is
but your class name is
this can never work with magento autoload. you will have to put your class into:
(or completely change the class name, whatever you may prefer)