我已将管理网格添加了类别过滤器,以下是代码
$cat_ids = implode(',', $CatIdArray['CategoryId']);
$collection->getSelect()
->join(array('ccp'=>'catalog_category_product'),
"ccp.product_id = e.entity_id AND ccp.category_id IN({$cat_ids})",
array('category_id')
);
现在问题是,当多个类别具有相同的产品时,它会崩溃,以避免这种情况
$collection->groupByAttribute('entity_id');
它返回了我不同的记录,但这打破了paginaion。我知道这是常见的问题,但任何帮助将不胜感激。感谢
答案 0 :(得分:4)
如果你面临逐个问题。我使用这种方式多次解决同样的问题。
从magento / lib / Varien / Data / Collection / Db.php复制Db.php文件
将其粘贴到本地目录,以便生成的文件夹结构如下所示:
magento / app / code / local / Varien / Data / Collection / Db.php
。
现在打开此文件以编辑并用下面的
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;
}.Try this , hope this will help you.
答案 1 :(得分:2)
而不是
$collection->groupByAttribute('entity_id');
使用此
$collection->getSelect()->group('entity_id');