Question

I currently have a extension that sets a hover on an image when ever it finds a label that is called 'hover'. I wish to change this to hover an image if there is an image with sort order id which is '2'. But I do not know how to do this. The code is below.

    $html = "";
    $imgcount = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages()->count();
    if ($imgcount>0):
        $_gallery = Mage::getModel('catalog/product') -> load($_product -> getId()) -> getMediaGalleryImages();
        foreach ($_gallery as $_image ):
            if ($_image->getLabel() == 'hover'):
                $html = '<span class="hover-image"><img ' . $this->getImgSources($_product, $imgType, $w, $h, $_image -> getFile()) . ' alt="" /></span>';
            break;
            endif;
        endforeach;
    endif;
    return $html;

I was hoping it would be as simple as if ($_image->getSortOrder() == 2): but that was just flawed thinking. Any ideas?

Was it helpful?

Solution

Try $_image->getPositionDefault()

print_r($_image->getData())

Array
(
    [value_id] =&gt; 2
    [file] => /l/a/label.jpg
    [label] => Label
    [position] => 0
    [disabled] => 0
    [label_default] => Label
    [position_default] => 0
    [disabled_default] => 0
    [url] => http://www.site.com/media/catalog/product/l/a/label.jpg
    [id] => 2
    [path] => /var/www/site/media/catalog/product/l/a/label.jpg
)

OTHER TIPS

R.S' answer works but I came across a simpler way for me to do it. I simple changed.

if ($_image->getLabel() == 'hover'):

to

if ($_image->getPosition() == 2):

Thanks for your help folks, wouldn't of came across this otherwise. I know it looks stupid, but in a panic I missed the most obvious thing in the world and that was the fix.

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