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

标签 zend-framework magento sql-order-by

我为 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;
}

感谢您的帮助。

最佳答案

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;
}

关于zend-framework - 如何在 Magento 查询中添加 "order by",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13957755/

相关文章:

mysql - 采埃孚 "Object of class Zend_Db_Table_Rowset could not be converted to string"

zend-framework - 为什么在 Zend Framework 2 中创建自定义表单元素时短名称不起作用?

magento - 如何更改 Magento 中的类别页面布局?

mysql - 在sql中对交叉表进行排序

MySQL以不同的排序顺序对多列进行排序

php - 苹果推送通知问题

php - 在Zend Framework中选择上个月的所有记录?

php - Magento 修改某些产品的产品可见性

javascript - Magento - 动态加载 CSS 和 JS

mysql - 如何在Update语句中使用Order by