我想知道是否有人在将订单商品表加入销售订单网格并且能够正确过滤后有多少运气?
我已经能够完成加入,如下所示:
protected function _prepareCollection()
{
parent::_prepareCollection();
$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'),
)
);
$collection->getSelect()->group('entity_id');
$this->setCollection($collection);
return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
}
但我现在正试图像这样添加列过滤器:
protected function _addColumnFilterToCollection($column)
{
if($this->getCollection() && $column->getFilter()->getValue())
{
if($column->getId() == 'skus')
{
$this->getCollection()->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR "|")'),
)
)->getSelect()
->group('`main_table`.entity_id')
->having('find_in_set(?, `main_table`.skus)', $column->getFilter()->getValue());
return $this;
}
if($column->getId() == 'names')
{
$this->getCollection()->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'names' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'),
)
)->getSelect()
->group('`main_table`.entity_id')
->having('find_in_set(?, names)', $column->getFilter()->getValue());
return $this;
}
}
return parent::_addColumnFilterToCollection($column);
}
每次我尝试过滤时都会收到此错误: “未找到列:1044未知列'main_table.names'在'having clause ...”。
如果您之前遇到此问题,请告诉我,您有什么指示吗?
答案 0 :(得分:1)
我有同样的问题,当我仔细看看问题时,我确实看到分页查询导致了错误。更改模型中的getSelectCountSql(),添加以下内容
$countSelect->reset(Zend_Db_Select::HAVING);
您的页面将会显示,但您必须更改getSelectCountSql()tot才能获得正确的页数和结果。