每个属性'country_of_manufacture'的magento产品计数

时间:2013-05-23 06:03:55

标签: php magento magento-1.7

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

  

India => 10,Shrilanka => 5,

如何在magento中实现它?

2 个答案:

答案 0 :(得分: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();

答案 1 :(得分:1)

而不是使用

count($collection)

你可以尝试

$collection->getSelect()->count();