我为 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/