I have created a query that would allow me to sort my products based on the quantity they have been ordered. But when I print the query, the quantity ordered is coming in Ascending order. I want to make it work in descending order. The query is as below
$toDate = date("Y-m-d h:m:s", strtotime('tomorrow') - 1);
$fromDate = date("Y-m-d h:m:s", strtotime("-1 months"));
$this->getSelect()->joinLeft(array('sfoi' => $this
->getTable('sales/order_item')),
"e.entity_id = sfoi.product_id AND sfoi.created_at BETWEEN
'{$fromDate}' AND '{$toDate}'",
array('qty_ordered' => 'SUM(sfoi.qty_ordered)'))
->group('e.entity_id')
->order("qty_ordered {$dir}");
return $this;
Can anyone kindly let me know how to do this? I just want to change the order of "qty_ordered" From ASC to DESC