So I am trying to add a new column in the Orders report.
I decided to get the orders by period, so I did this $order_id = $row->getData('period');
Then I tried to load the orders using
$sales_model = Mage::getModel('sales/order')->load($order_id);
$subtotal = $sales_model->getSubtotal();
$items = $sales_model->getAllItems();
But it won't work. I tried outputting $sales_model
and it's empty.
Thanks in advance!
EDIT:
From ProxiBlue (still returns nothing):
<?php
class Mage_Adminhtml_Block_Report_Sales_Grid_Column_Renderer_Profit extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
public function render(Varien_Object $row)
{
$fromDate = date('Y-m-d H:i:s', strtotime($fromDate));
$toDate = date('Y-m-d H:i:s', strtotime($toDate));
/* Get the collection */
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate))
->addAttributeToFilter('status', array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE));
return $orderCollection;
}
}
Best Answer
Ok,
Firstly I think you are not understanding what Models and Collections are. There is no attribute, or value called period. Not sure where you got that from.
A model as in
Mage::getModel('sales/order')
will be an object containing the relevant data of one item. Generally that is laoded directly by the entity_id of the order that you are interested in. (->load($order_id)
)So, considering the code you supplied in your question, what you have tried would not work, as you are wanting back a
Collection
ofModels
So, to get a collection, you would use
Mage::getModel('sales/order')->getCollection()
, and then apply filters to that collection (in your case date ranges). You would then be able to iterate the collection, and deal with each model held in the collection in any way you want.To answer your question:
you woudl then do something with the collection.
Hope that helps.
EDIT1:
To test the query, output the raw sql, and run it in a mysql client.