3

I'm pretty new to magento so i'm not sure how to make the call to get all the media info for each product.

I currently have this call that gets all the products and the data on the product model, but I also need the media info.

Any help would be great.

$products_collection = Mage::getModel('catalog/product')
            ->getCollection()
            ->addAttributeToSelect('*')
            ->addStoreFilter(Mage::app()->getStore()->getId());
  • I am not sure , but do you want product image urls? – Vivek Kumar Jul 6 '18 at 23:17
  • Yes, that is one thing I will need. – Chris Jul 7 '18 at 1:20
1

Make use of this sample code to get media information of a product.

$products_collection = Mage::getModel('catalog/product')
            ->getCollection()
            ->addAttributeToSelect('*')
            ->addStoreFilter(Mage::app()->getStore()->getId());

foreach ($products_collection as $product) {
    $productGalleryImages = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages();

    foreach ($productGalleryImages as $image) {
       var_dump($image); /* Write your logic here */
    } 
}
| improve this answer | |
1

This should be bit faster ...

$products = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addStoreFilter(Mage::app()->getStore()->getId());

foreach ($products as $product) {
    $product->getResource()->getAttribute('media_gallery')->getBackend()->afterLoad($product);
    foreach ($product->getMediaGalleryImages() as $image) {
        var_dump($image->getData());
    }
}
| improve this answer | |

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.