且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Magento集合GroupBy getSize

更新时间:2023-11-30 10:44:58

首先,感谢Guerra的回复。你指向我的方向正确。

First, thanks Guerra for your reply. You pointed me into the right direction.

我刚刚解决了几个小时后..诀窍是添加一个过滤器到资源集合 XXXXX_Downloads_Model_Mysql4_Files_Collection

I just solved it after a couple of hours.. the trick was to add a filter into the resource collection XXXXX_Downloads_Model_Mysql4_Files_Collection

public function addGroupByNameFilter()
{
    $this->getSelect()->group('main_table.name');
    return $this;
}

应用此过滤器:

$this->_totalItems = Mage::getModel('downloads/files')
        ->getCollection()
        ->addFieldToFilter('customer_groups', array('like' => '%'.$customergroupId.'%'))
        ->addFieldToFilter('main_table.is_active', 1)
        ->addGroupByNameFilter()
        ->getSize()

这样我会保留我的 XXXXXXX_Downloads_Model_Mysql4_Files_Collection 对象。 :)

works like a charm! That way I will keep my XXXXXXX_Downloads_Model_Mysql4_Files_Collection object. : )

干杯,

Martijn