Magento - get product collection of all products

Magento - get product collection of all products

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Retrieving All Products in Magento Without a Category Filter

When displaying a product grid on a CMS page in Magento, the standard catalog/product_list block is often sufficient for simple use cases. However, scenarios arise where you need to bypass category logic entirely to list every item in the store. This is common when managing large catalogs—like a store with 8,000 products—where creating a single "All Products" category is either impractical or violates your site architecture.

The default behavior of the Product_List block relies on the catalog/product_list.xml layout handle to load a collection. If no specific filter is applied, Magento defaults to showing products from the currently selected category. To display all items regardless of category assignment, you must intervene in the collection retrieval process.

Overriding the Product Collection Logic

The most direct approach involves overriding the Mage_Catalog_Block_Product_List block within your custom module. You need to target the protected method _getProductCollection(), which constructs and returns the data for the grid.

By creating a class that extends Mage_Catalog_Block_Product_List, you can intercept the collection before it is rendered. The core logic resides in ensuring the collection's category filter is cleared and setting a flag to indicate that all products should be returned.

Here is an example of how the override class might look:

class My_Module_Block_Catalog_Product_List extends Mage_Catalog_Block_Product_List
{
    protected function _getProductCollection()
    {
        $collection = parent::_getProductCollection();

        // Clear any existing category filters to ensure we get all products
        foreach ($collection->getLayerData() as $filter) {
            if (isset($filter['attribute']) && $filter['attribute'] == 'category_id') {
                $collection->getCategoryFilter()->clear();
            }
        }

        // Alternatively, explicitly set the filter to return all categories or clear it via collection config
        // depending on the specific Magento version and layer state.
        
        return $collection;
    }
}

Handling Layer State and Filters

A critical nuance in Magento's catalog system is the "Layered Navigation" state. When a block loads, it often inherits filter data from the request parameters or the current page context. Even if your CMS page URL does not specify a category, the collection might still be scoped by default settings or previous navigation states.

In older versions of Magento (Community Edition 1.x), simply calling clear() on the category filter within _getProductCollection() is often enough. However, you must ensure that the collection's setCategoryFilter method is not implicitly re-applying a single-root category filter.

If using Magento 2, the approach shifts slightly due to changes in how blocks are loaded and collections managed. Instead of overriding a protected block method directly (which can be fragile across upgrades), it is often better to use a layout XML update to inject a custom collection or modify the collection object definition within the .phtml template if you have full control over it.

Configuration and Template Adjustments

If modifying the block class feels too heavy-handed or risks breaking during future core updates, consider adjusting the block initialization in your layout XML file. You can set the collection's filter to return all categories by specifying a specific configuration for the catalog/product_list block handle.

Alternatively, if you prefer not to override the block at all, you can define a custom template that manually instantiates a new product collection:

<?php
$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->setPageSize(30); // Adjust as needed for performance
?>

This method is less intrusive but requires you to handle the rendering loop yourself, which might deviate from the standard grid layout expectations.

Performance Considerations

Retrieving 8,000 products in a single go can severely impact server response times and database load. Before implementing this globally, evaluate whether displaying that many items at once is necessary for the user experience. If you must show all products, ensure your collection includes only necessary fields using addAttributeToSelect with specific attributes rather than loading the default set, which often includes verbose data like descriptions, images, and pricing metadata.

Additionally, consider implementing pagination explicitly even if the block supports it by default, to prevent memory exhaustion on large datasets. Always test the resulting page load time under production-like conditions before deploying such a change to live traffic.

Our network