1

At the moment I'm using the following code to get the image by position. Is there an easiest way to do that?

<?php 
$imgFile = $imgLabel = "";
$imagens = Mage::getModel('catalog/product')->load($_item->getProductId())->getMediaGalleryImages();
foreach ($imagens as $imagem) {
if($imagem->getPosition() === '9') :
    $imgFile = $imagem->getFile();
    $imgLabel = $imagem->getLabel();
    endif;
}
if(!$imgFile && !$imgLabel):
?>
<img src="<?php echo $this->helper('catalog/image')->init(Mage::getModel('catalog/product')->load($_item->getProductId()), 'small_image')->resize(70,105); ?>" width="70" height="105" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />
<?php else : ?>
<img src="<?php echo $this->helper('catalog/image')->init(Mage::getModel('catalog/product')->load($_item->getProductId()), 'small_image', $imgFile)->resize(70, 105); ?>" width="70" height="105" alt="<?php echo $this->htmlEscape($imgLabel);?>" />
<?php endif; ?>
2

I recently needed to do this as well... here's how I got to it:

$_product->getMediaGalleryImages()->getItemByColumnValue('position_default', 'Your Position')->getUrl();

Hope that helps you!

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.