I need a unique ID for each image in Magento store for a special use case.
So I'm trying to figure a way to reliably obtain the product image ID. Is that the $image["value_id"]
field?
I tried this:
foreach ($collection as $product) {
$imageUrl = (string)Mage::helper('catalog/image')->init($product, 'image')->resize(480);
$galleryData = $product->getMediaGalleryImages();
foreach($galleryData as $image) {
$imageId = $image['value_id'];
}
}
Sometimes it works, sometimes it returns null, even when $imageUrl has a valid URL for the image. Is that because an image with a single product photo doesn't have a media gallery?
I need a reliable way to get the image ID for every product that has an image.