Skip to content

Instantly share code, notes, and snippets.

@antiseptikk
Last active February 20, 2019 14:20
Show Gist options
  • Save antiseptikk/ed988c46938e3846e00621c8d5f55440 to your computer and use it in GitHub Desktop.
Save antiseptikk/ed988c46938e3846e00621c8d5f55440 to your computer and use it in GitHub Desktop.
<?php
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter('col', array('eq' => $value));
// Add a page size to the result set.
$collection->setPageSize(25);
$pages = $collection->getLastPageNumber();
$currentPage = 1;
do {
// Tell the collection which page to load.
$collection->setCurPage($currentPage);
$collection->load();
foreach ($collection as $item) {
// do stuff
// tip to save memory
// $_child = Mage::getModel('catalog/product')->load($child->getId());
// $_child->clearInstance();
}
// make the collection unload the data in memory so it will pick up the next page when load() is called.
$collection->clear();
$currentPage++;
} while ($currentPage <= $pages);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment