我需要根据属性'country_of_manufacture'计算/分组/选择产品。 像这样
India => 10,Shrilanka => 5,
如何在magento中实现它?
答案 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();