Magento – How to Get Large Collection of Products

magento-1.7magento-1.8magento-1.9magento-enterprise

I have a store with over 100K products. I am using this code to get all my products.

$model = Mage::getModel('catalog/product')->getCollection();
foreach ($model  as $product) {
     $p = Mage::getModel('catalog/product')->load($product->getId());
     echo $p->getName();
     echo $p->getDescription();
     echo $p->shortDescription();
}

But it shows nothing. This code works where i have only less number of products in my store.
So how to get all my 100K products?
Thank you

Best Answer

$model = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect(array('name', 'descryption','short_descryption'))
    ->setPageSize(1000);
$numberOfPages = $model->getLastPageNumber();

for ($i=1; $i<=$numberOfPages; $i++) {
    $products = $model->setCurPage($i)->load();
    foreach ($products as $product) {
        echo $product->getName() . '<br />'; 
        echo $product->getDescription() . '<br />'; 
        echo $product->shortDescription() . '<br />';
    }
}
Related Topic