Sorry for my English

I have this code

$productCollection = Mage::getModel('catalog/product')
        ->addAttributeToFilter('attribute_set_id', array(12, 4))
        ->addAttributeToFilter('qty', array("gt" => 0))

how can i get the number of images of this product or just get the product images. I would like to avoid the situation receiving pictures when the loop is running because it is database load


Add just this code in your collection.


add this code if count the amount of each product

->groupByAttribute('your attribute')

You got a few more options

If you want main image url

$collection = Mage::getModel('catalog/product')->getCollection();

foreach ($collection as $product) {

Or this. Or did you mean avoid doing this? Not sure. It will be extra load yes but you need the galley info so additional load is necessary.

$collection = Mage::getModel('catalog/product')->getCollection();

$backendModel = $collection->getResource()->getAttribute('media_gallery')->getBackend();

foreach($collection as $product){
    $backendModel->afterLoad($product); //adding media gallery to the product object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.