I need some help.
I created a custom report in Magento. Now I want to list all products wich have been ordered in a month in my grid. In my report are the following columns: SKU, Name, Ordered Quantity and Base Cost.
In the column "Ordered Quantity" I want to show how often a product has been ordered. In the column "Base Cost" I want to show the total base costs (ordered quantity * base cost).
With the following code I get so correct product names and skus. The other columns are not correct.
Can someone help me?
$this->getSelect()->reset()
->from(
array('order_items' => $this->getTable('sales/order_item')),
array(
'ordered_qty' => 'SUM(order_items.qty_ordered)',
'order_items_name' => 'order_items.name',
'base_cost' => 'SUM(order_items.base_cost)',
'sku' => 'order_items.sku'
))
->where("created_at BETWEEN '".$from."' AND '".$to."'")
->where('parent_item_id IS NULL')
->group('order_items.product_id')
->having('SUM(order_items.qty_ordered) > ?', 0)
->order(
array(
'SUM(order_items.qty_ordered) DESC'
));