1

我需要根据属性“country_of_manufacture”计算/分组/选择产品。像这样

印度 => 10,什里兰卡 => 5,

如何在magento中实现它?

4

2 回答 2

3
    $collection = $this->getLoadedProductCollection()
        ->addAttributeToSelect('*')
        ->addExpressionAttributeToSelect('total_country_of_manufacture',"COUNT({{entity_id}})",'entity_id')
        ->groupByAttribute('country_of_manufacture');

计数

Mage::getModel('catalog/product')->getCollection()->groupByAttribute('country_of_manufacture')
                ->addExpressionAttributeToSelect("cnt_product",'COUNT({{entity_id}})', 'entity_id')
                ->load();
于 2013-05-23T06:25:57.880 回答
1

而不是使用

count($collection)

你可以试试

$collection->getSelect()->count();
于 2013-05-23T09:43:39.820 回答