Answer the question
In order to leave comments, you need to log in
How to display image attribute value in Magento?
1. There is a product page
2. There is a block output on this page of the type = catalog/product_view_media
3. There is a method that receives a list of images in this block $this->getGalleryImages()
4. Each image can refer to Base Image / Small Image / Thumbnail / [custom media attributes]
The question is: how to get the type (Base Image / Small Image / ...) that an image belongs to from the resulting collection using $this->getGalleryImages() ?
Answer the question
In order to leave comments, you need to log in
Not directly. Does not contain a collection of required information:
/**
* Retrive media gallery images
*
* @return Varien_Data_Collection
*/
public function getMediaGalleryImages()
{
if(!$this->hasData('media_gallery_images') && is_array($this->getMediaGallery('images'))) {
$images = new Varien_Data_Collection();
foreach ($this->getMediaGallery('images') as $image) {
if ($image['disabled']) {
continue;
}
$image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
$image['id'] = isset($image['value_id']) ? $image['value_id'] : null;
$image['path'] = $this->getMediaConfig()->getMediaPath($image['file']);
$images->addItem(new Varien_Object($image));
}
$this->setData('media_gallery_images', $images);
}
return $this->getData('media_gallery_images');
}
$_product->getImage() # /a/s/asics-men-s-gel-kayano-xii.jpg
$_product->getSmallImage() # /a/s/asics-men-s-gel-kayano-xii-2.jpg
$_product->getThumbnail() # /a/s/asics-men-s-gel-kayano-xii-2.jpg
...
$_image->getFile() # в цикле даст список путей выше,
# если только изображение не исключено из коллекции в бэкэнде
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question