Guerra
Guerra

Reputation: 2790

getCollection() returns 1 value on frontend and multiples on backend

I have thhis code on my model:

$categorias = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('status', 1)
        ->addAttributeToFilter('visibility', 4)
        ->groupByAttribute('name');

on my backend page this returns all the products values grouped by name, but if i call this on frontend just return 1 value. What's going on? If i remove groupByAttribute line work's fine but don't group. I need group. Ty for help guys

Upvotes: 2

Views: 615

Answers (2)

Josua M C
Josua M C

Reputation: 3158

remove your groupByAttribute();

$categorias = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('status', 1)
        ->addAttributeToFilter('visibility', 4)
               //removed ->groupByAttribute('name')
        ;
$categorias->getSelect()->group('name');  //added

try:

 $collection->getSelect()->group($fieldname); 

if you want to group by more than one field then:

 $categorias->getSelect()->group(array($fieldname1, $fieldname2,...)); 

Upvotes: 2

pzirkind
pzirkind

Reputation: 2338

Are all the categories enabled on the frontend? It could be they are not and therefore only coming up in backend results.

Pesach

Upvotes: 0

Related Questions