$collection = Mage::getResourceModel('catalog/product_collection');

If I echo count($collection); I get the expected response. However, if prior to that


I get a zero size on the collection count. What is causing this?

  • please try this $collection->count(); – Amit Bera Jan 19 '15 at 8:25
  • Either way (echo count($collection); or echo $collection->count();) it returns zero (0). – Moose Jan 19 '15 at 8:55
  • please reindex the system – Amit Bera Jan 19 '15 at 9:36

You can analyze your SQL query before and after


by using this line

<?php echo (string)$collection->getSelect(); ?>
  • Before: SELECT 'e'.* FROM 'catalog_product_entity' AS 'e' and after: SELECT 'e'.*, 'price_index'.'price', 'price_index'.'tax_class_id', 'price_index'.'final_price', IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS 'minimal_price', 'price_index'.'min_price', 'price_index'.'max_price', 'price_index'.'tier_price' FROM 'catalog_product_entity' AS 'e' INNER JOIN 'catalog_product_index_price' AS 'price_index' ON price_index.entity_id = e.entity_id AND price_index.website_id = '0' AND price_index.customer_group_id = 0 – Moose Jan 19 '15 at 8:57
  • Your query is correct, try to run it using MySQL client (HeidiSQL for example) to see the result https://www.evernote.com/shard/s411/sh/f9b878d2-edd8-4614-b3d4-4e33e20f15d0/efd8f6988365d439e5a2e929287de49e – Vasyl Malanka Jan 19 '15 at 10:03

Try reindexing your shop (catalog_product_price).

I have experienced a similar problem when I created a new website in Magento and attached products to it. Because the indexer did not run, the prices were unknown in the database as well. And if they are unknown, your product will not be picked up in the productCollection and will be empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.