如何在Magento查询中添加"order by"

use*_*533 2 zend-framework sql-order-by magento

我为magento安装了一个脚本.它允许在订单上添加注释.所以它显示了对订单网格的一个评论.

问题是它没有按"created_at"列对注释进行排序.我不知道如何设置顺序.

这是代码的一部分:

 protected function _initSelect()
{
    parent::_initSelect();

    // Join order comment
    $this->getSelect()->joinLeft(
        array('ordercomment_table' => $this->getTable('sales/order_status_history')),
        'main_table.entity_id = ordercomment_table.parent_id AND ordercomment_table.comment IS NOT NULL',
        array(
            'ordercomment' => 'ordercomment_table.comment',
        )
    )->group('main_table.entity_id');

    return $this;
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

ben*_*rks 5

protected function _initSelect()
{
    parent::_initSelect();

    // Join order comment
    $this->getSelect()->joinLeft(
        array('ordercomment_table' => $this->getTable('sales/order_status_history')),
        'main_table.entity_id = ordercomment_table.parent_id AND ordercomment_table.comment IS NOT NULL',
        array(
            'ordercomment' => 'ordercomment_table.comment',
        )
    )->group('main_table.entity_id');

    //Add ORDER BY
    $this->getSelect()->order(array('ordercomment_table.created_at DESC'));

    return $this;
}
Run Code Online (Sandbox Code Playgroud)