使用group()中断了magento中的getSelectCountSql [英] using group() breaks getSelectCountSql in magento
本文介绍了使用group()中断了magento中的getSelectCountSql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用
$collection->getSelect()->group('entity_id')
或
$collection->groupByAttribute('entity_id')
它破坏了getSelectCountSql,我得到1条记录和1页. Magento确实
It breaks getSelectCountSql and I'm getting 1 record and 1 page. Magento does
$countSelect->columns('COUNT(DISTINCT e.entity_id)');
有办法解决吗?
我在覆盖Mage_Adminhtml_Block_Catalog_Product_Grid的_prepareCollection时遇到了它
I run into it,While overriding _prepareCollection of Mage_Adminhtml_Block_Catalog_Product_Grid
谢谢
推荐答案
我更新了 lib/Varien/Data/Collection/Db.php 文件以允许执行此操作.您必须跟踪此升级,但它可以工作.
I updated the lib/Varien/Data/Collection/Db.php file to allow this as I had to have it work. You'll have to keep track of this for upgrades but it works.
public function getSelectCountSql()
{
$this->_renderFilters();
$countSelect = clone $this->getSelect();
$countSelect->reset(Zend_Db_Select::ORDER);
$countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
$countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
$countSelect->reset(Zend_Db_Select::COLUMNS);
// Count doesn't work with group by columns keep the group by
if(count($this->getSelect()->getPart(Zend_Db_Select::GROUP)) > 0) {
$countSelect->reset(Zend_Db_Select::GROUP);
$countSelect->distinct(true);
$group = $this->getSelect()->getPart(Zend_Db_Select::GROUP);
$countSelect->columns("COUNT(DISTINCT ".implode(", ", $group).")");
} else {
$countSelect->columns('COUNT(*)');
}
return $countSelect;
}
这篇关于使用group()中断了magento中的getSelectCountSql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文