I need to change the order grid in the admin area, and add in a column for Margin (ie, total margin on each order). I have set up code\local\MageWorx\Adminhtml\Block\Orderspro\Sales\Order\Grid.php with
$this->addColumn('margin', array(
'renderer' => 'mageworx/orderspro_sales_order_grid_renderer_margin',
'type' => 'currency',
'currency' => 'order_currency_code',
'header' => $helper->__('Margin'),
'index' => 'total_margin'
));
Then I have Sales\Order\Grid\Renderer\Margin.php which has the following:
class MageWorx_Adminhtml_Block_OrdersPro_Sales_Order_Grid_Renderer_Margin extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$orderItems = Mage::getModel('sales/order')->getCollection();
$totalMargin = 0;
foreach ($orderItems as $item) {
$totalMargin += $totalMargin->getMarginR();
}
return $totalMargin;
}
public function getMarginR()
{
//each individual margin
$x = 0;
$x = ($this->getPrice() * $this->getqty_ordered()) - ($this->getData(mage::helper('purchase/MagentoVersionCompatibility')->getSalesOrderItemCostColumnName()) * $this->getqty_ordered());
return $x;
}
}
This just gives me a blank page.
If I take out the foreach loop and just have something like this:
$orderItems = Mage::getModel('sales/order')->getCollection();
$totalMargin = "hi";
//foreach ($orderItems as $item) {
// $totalMargin += $totalMargin->getMarginR();
// $totalMargin = 1;
//}
return $totalMargin;
I get "hi" in each field, so I think the getCollection bit is working, I think the problem is in the foreach. Even if I take out the
$totalMargin += $totalMargin->getMarginR();
line and just try to loop and do nothing of consequence it just gives a blank page.
Fairly new at this but what am I missing? Thanks. Could it be that the collection is empty, am I calling it wrong?
var/log/system.log has nothing.
} – hawthorn Jun 10 '16 at 14:53