Search code examples
magentoreport

Add a total column from two other existed column magento product sold report


I am working on magento product sold report. Currently, I have 2 existed columns, which are price and ordered_quantity. I want to add a column called "total cost", which is equal to price * ordered_quantity. But I don't know how. This is my code. Please help!

$this->addColumn('ordered_qty', array(
     'header'    =>Mage::helper('reports')->__('Quantity Ordered'),
     'width'     =>'120px',
     'align'     =>'right',
     'index'     =>'ordered_qty',
     'total'     =>'sum',
     'type'      =>'number'
));
//Unit price column
$this->addColumn('price', array(
     'header'    =>Mage::helper('reports')->__('Unit Price'),
     'width'     =>'200px',
     'index'     =>'price',
     'align'     =>'right'
));
//Total money column
$this->addColumn('total', array(
     'header'    =>Mage::helper('reports')->__('Total'),
     'width'     =>'200px',
     'index'     => 'total',//This returns null
     'total'     =>'sum',
     'align'     =>'right',
     'type'      =>'number'
));

Solution

  • I found the answer. Using a render custom can work perfectly. Here is my code.

    public function render(Varien_Object $row)
          {                                  
              $price = $row->getPrice();
              $orderedQty=$row->getOrderedQty();         
              $total = $price * $orderedQty;
              return $total;
          }