magento get products per page for category list

magento get products per page for category list

September 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
magento get products per page for category list

Retrieving Products Per Page for Category List in Magento

As a senior developer, I understand your need to limit the product collection based on the settings configured in your Magento store. Let’s dive into how you can retrieve the products per page on grid setting values and apply them to your product collection.

Accessing the Configurable Setting Values

Magento stores these settings in its configuration files. To access the default value for products per page on grid, you can use the following code:

$defaultValue = Mage::getStoreConfig('catalog/frontend/grid_per_page_default');

Similarly, to get the allowed values for this setting, you would use:

$allowedValues = explode(',', Mage::getStoreConfig('catalog/frontend/grid_per_page_values'));

Limiting Your Product Collection

Now that we have the configuration values, let’s modify your getLoadedProductCollection method to incorporate these settings. Here’s an updated version of your code:

public function getLoadedProductCollection()
{
    $collection = Mage::getModel('catalog/product')->getCollection();
    $categoryId = $this->getCategory()->getId();

    // Filter by category
    if ($categoryId) {
        $collection->addCategoryFilter($categoryId);
    }

    // Add all attributes to select
    $collection->addAttributeToSelect('*');

    // Set the page and limit based on config values
    $defaultLimit = (int) Mage::getStoreConfig('catalog/frontend/grid_per_page_default');
    if ($defaultLimit > 0) {
        $currentPage = 1; // Assuming you want to start from the first page
        $collection->setPage($currentPage, $defaultLimit);
    }

    $collection->load();

    return $collection;
}

Best Practices and Further Considerations

  1. Pagination: If you want to support pagination, consider using Zend_Paginator or a Magento-specific paginator like the one provided by Magento.

  2. Performance Optimization: When dealing with large product collections, it’s important to optimize your queries. Only select the necessary attributes and use appropriate filters.

  3. Caching: If you’re dealing with frequently accessed category lists, consider implementing caching mechanisms to improve performance.

Conclusion

In this post, we explored how to retrieve the products per page on grid configuration values from Magento and integrate them into your product collection logic. By following the provided code examples, you can now easily limit your product collections based on these settings.

Remember, proper pagination and performance optimization are crucial when dealing with large product lists in Magento. By keeping these best practices in mind, you’ll create a more efficient and user-friendly shopping experience for your customers.

For further insights into Magento development and other relevant topics, feel free to explore our blog at https://laravelcompany.com. We regularly publish comprehensive guides and tutorials to help developers like yourself succeed in their projects.

Catalog Admin Configuration

Our network