Magento后台Grid表使用了Group By导致统计出错的解决办法
来源:互联网 发布:极客学院php就业班视频 编辑:程序博客网 时间:2024/05/17 07:00
Wrong Count in Admin Grid When Using Group By : Magento
If you have noticed or not, in edition 1.5 of Magento when you use GROUP BY clause in any Grid.php file in admin, the count always display wrong. Many times it displays 1 even if there are hundreds of records. Due to this your pagination also doesn’t work. This is a bug in Magento. Your getSize() always returns wrong count whereas total records in grid are proper.
To fix this, you need to edit one of your core file. As it’s not a good practice to edit core file, we will here override the core file.
Overriding LIB module
Copy Db.php file from
MAGENTO_FOLDER / lib / Varien / Data / Collection / Db.php
Paste it to your local directory so the resultant folder structure would look like this:
MAGENTO_FOLDER / app / code / local / Varien / Data / Collection / Db.php
Now open this file to edit and replace getSelectCountSql function with below one
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); 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; }
Google了一下,解决的办法可以是重写MAGENTO_FOLDER / lib / Varien / Data / Collection / Db.php里面的getSelectCountSql()方法,拷贝原文件到本地代码池MAGENTO_FOLDER / app / code / local / Varien / Data / Collection / Db.php,并进行修改。
如果不想重写Varien Db.php代码,还可以这么改:
可以在你Grid表所用的collection里面增加这个getSelectCountSql()方法,代码同上,覆盖该方法。
- Magento后台Grid表使用了Group By导致统计出错的解决办法
- magento Access denied 由于权限分配失误导致不能进入magento后台的解决办法!
- magento中使用group,order by,limit
- magento 后台订单grid表获取shipping_description
- 使用group by 统计的排行榜时,加上一个序号
- group by的使用
- group by的使用
- group by 的使用
- group by 的使用
- group by的使用
- group by的使用
- group by的使用
- group by的使用
- Magento 后台menu不能进入的解决办法
- magento -- 如何修改后台列表(Grid)的默认行数
- group by 统计行数
- group by 统计行数
- Group By的扩展使用
- 菜鸟配置hadoop-简单源代码
- Leetcode NO.41 First Missing Positive
- 在辞职后的旅途中:我写了个App 创立了一家公司
- 线程中 this逃逸
- Spring WebSocket教程(一)
- Magento后台Grid表使用了Group By导致统计出错的解决办法
- Java与.NET DES加密解密互转[转载]
- Hbase入门之:原理、基本概念与架构
- Bash+R: howto pass parameters from bash script to R
- xxxHive-3-日常操作xxxHive总结
- Android App 性能优化(一)
- JS(四)DOM模型之属性样式
- java 设置代理网络
- hdoj 1021 Fibonacci Again