How do I use setPage() in an non-EAV model in Magento for pagination/limiting?

How do I use setPage() in an non-EAV model in Magento for pagination/limiting?

September 9, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How do I use setPage() in an non-EAV model in Magento for pagination/limiting?

Solving Pagination Issues with Non-EAV Models in Magento

In the world of e-commerce development using Magento, pagination is a fundamental feature that helps manage large datasets efficiently. While the setPage() method works seamlessly with Entity-Attribute-Value (EAV) models, you might face challenges when applying it to non-EAV models.

Understanding the Problem

Magento’s built-in EAV architecture allows for dynamic attribute definition and storage, which is why setPage() works directly on those objects. However, custom or traditional relational models don’t inherit this behavior by default.

For instance, consider a scenario where you have a custom model like ProductReview, which doesn’t follow the EAV structure:

$reviews = Mage::getModel('review/review')->getCollection();
$reviews->setPage(0, 10);

This code snippet might not produce the expected results. The setPage() method expects a collection with an EAV-enabled model.

A Step-by-Step Solution

To resolve this issue, we need to manipulate the underlying SQL query directly. Here’s how you can achieve pagination in your non-EAV models:

1. Fetch the Collection

First, retrieve your data using the core Magento functionality:

$reviews = Mage::getModel('review/review')->getCollection();

2. Apply Custom Limit

Since setPage() isn’t working as expected, you can use the getSelect() method to manipulate the underlying query:

$limit = 10; // Number of items per page
$offset = 0; // Starting point for pagination

$reviews->getSelect()
    ->limit($limit)
    ->offset($offset);

3. Fetch Data

Now, you can fetch your paginated data:

$paginatedReviews = $reviews->fetchAll();

If you prefer a more object-oriented approach, you can create a utility method within your model class:

class My_ProductReview_Model_Resource extends Mage_Core_Model_Resource_Db {
    public function getPaginatedData($limit, $offset) {
        $collection = $this->getCollection();
        $collection->getSelect()->limit($limit)->offset($offset);
        return $collection->fetchAll();
    }
}

You can then call this method from your controller or other models:

$paginatedReviews = Mage::getModel('review/review_resource')->getPaginatedData(10, 0);

Best Practices and Considerations

When dealing with pagination in Magento, consider the following best practices:

  • Use setPage() for EAV models where possible.
  • For non-EAV models, use getSelect()->limit($limit)->offset($offset) as shown above.
  • If your model requires complex filtering or sorting before pagination, create a separate method to handle this logic first.
  • Always test your pagination thoroughly on different datasets.

Conclusion

In this post, we’ve explored the challenges of using setPage() with non-EAV models in Magento and provided a practical solution. By understanding how to manipulate the underlying SQL query directly, you can apply pagination effectively to any model within your e-commerce application.

For more advanced techniques and best practices for Magento development, don’t forget to check out our guides at Laravel Company.

Catalog Database Themes Errors

Our network