2

How can I create a collection to get all products with the same name (grouped by name) and the same category (grouped by category) in the same collection ??

Thanks a lot for help.

Bizboss
  • 7,792
  • 27
  • 109
  • 174

1 Answers1

0

I am not sure if I understand clearly what you want. You can group products by name using groupByAttribute method:

$_collection = Mage::getModel('catalog/product')->getCollection();
$_collection->addAttributeToSelect('*');
$_collection->groupByAttribute('name');

But grouping by category is not that simple, since one product can be in more categories. So I am not sure if it is possible, you will probably have to write some checking script logic.


But maybe, you want just get products by name with

$_collection->addAttributeToFilter('name', 'My product name')

And get products by category: Magento products by categories


Read more about collections in Magento: http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento

Community
  • 1
  • 1
MattSkala
  • 1,069
  • 1
  • 10
  • 10
  • Thank you a lot, my problem is with the grouping by categories, I have tried to make a join with the table eav_attribute, and the column ´category_ids´ but, I get always ‘e.category_ids’ in ‘where clause’.... Any more help ? – Bizboss May 24 '12 at 07:09