I have heard many times that they both are the same. But I am facing a weird issue, in the product collection of CatalogSearch module, count() is returning correct product count while getSize() is returning zero.
So, basically this is what I am getting:
$collection->count(); //correct count
$collection->getSize(); //0
But I want the getSize() to have correct count as it decides whether to show pagination and products in the search page or not. I am using Inner Join, Left Join and Where condition only in the collection to be more specific.
Any ideas why I am getting this weird issue?
Thanks
UPDATE:
My previous question, How to clone the collection in Magento? I wanted to perform two different operations on one collection. The first collection shows correct getSize(), but then if the getSize() is zero, I removed the WHERE clause and gave new WHERE condition. After this, I am getting correct raw SQL what I expected, and running it in MySQL also gives a correct set of records, but only getSize() on the collection is giving zero counts.
So basically I may need to reload the collection, as getSize() is taking old count. Makes sense?
getSize()? Thanks! – MagExt May 23 '13 at 12:04CatalogSearchmodule there is nothing that overridesgetSize()orgetSelectCountSql(). It should work by default, unless you added some custom code. Can you post the way you build the collection? – Marius May 23 '13 at 12:08_totalRecords. You can try to clone the collection before callinggetSize()on the original collection. Maybe that will work. – Marius May 23 '13 at 12:19$sql = $collection->getSelectCountSql(); return $collection->getConnection()->fetchOne($sql);– koosa Nov 18 '16 at 00:43