Question

I want to get the image path and position of all images of each product. Therefore I load all media data:

$p = Mage::getModel('catalog/product')->load($productId);
//get all images
$mediaGallery = $p->getMediaGallery();

But if I dump the data I don't see any information which image is thumbnail, small or base?

Array
(
[images] => Array
    (
        [0] => Array
            (
                [value_id] => 1
                [file] => /b/o/log_mouse1.jpg
                [label] => Computer Mouse
                [position] => 1
                [disabled] => 0
                [label_default] => Mouse Logitech Laser
                [position_default] => 1
                [disabled_default] => 0
            )

        [1] => Array
            (
                [value_id] => 9
                [file] => /b/o/imagpro2012.jpg
                [label] => iMac Pro 2013
                [position] => 2
                [disabled] => 0
                [label_default] => iMac Pro
                [position_default] => 2
                [disabled_default] => 0
            )

        [2] => Array
            (
                [value_id] => 5
                [file] => /b/o/glasses1.jpg
                [label] => Glasses
                [position] => 3
                [disabled] => 0
                [label_default] => Glasses_def1
                [position_default] => 3
                [disabled_default] => 0
            )

Did I choose the wrong approach? How can I load image path and position of all 3 images (thumbnail, small image, image)? Thank you so much in advance!

Was it helpful?

Solution

You can get the image, thumbnail and any other image attribute value from the product directly.

$image = $product->getImage();
$thumb = $product->getThumbnail();
....

Try to view product and image as 2 separate entities in a 0 to n relation.
A product can have o to n associated images.

But the image, thumbnail and small image are product attributes. They have no meaning in relation to the media gallery.

So you cannot get the value of image attributes based on media gallery values only.
If you need to find which media gallery acts as small image you can loop through the media gallery images and compare the $image['file'] with $product->getSmallImage()

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top