0

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.

1

1 Answer 1

1

I tested on my local Magento 1.9 and I could get $image['value_id'] if there is any image in the product even if it is single image.

I didn't get $image['value_id'] when there is no image in the product, (placeholder image is displayed for the product).

If there is no image in the product, even then you get value for $imageUrl and that will be the image url of placeholder image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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