Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if product image is base image?

Tags:

magento

I got all images of a product by

Mage::getModel('catalog/product')->load($prod->getId())->getMediaGalleryImages()->getItems();

Here is the content of one item:

<i>protected</i> '_data' <font color='#888a85'>=&gt;</font> 
    <b>array</b> <i>(size=11)</i>
      'value_id' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'204'</font> <i>(length=3)</i>
      'file' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'/m/a/magento-red-furniture-set.jpg'</font> <i>(length=34)</i>
      'label' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'test label'</font> <i>(length=10)</i>
      'position' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'0'</font> <i>(length=1)</i>
      'disabled' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'0'</font> <i>(length=1)</i>
      'label_default' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'test label'</font> <i>(length=10)</i>
      'position_default' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'0'</font> <i>(length=1)</i>
      'disabled_default' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'0'</font> <i>(length=1)</i>
      'url' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'http://work.my/m1702/media/catalog/product/m/a/magento-red-furniture-set.jpg'</font> <i>(length=76)</i>
      'id' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'204'</font> <i>(length=3)</i>
      'path' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'/var/www/m1702/media/catalog/product/m/a/magento-red-furniture-set.jpg'</font> <i>(length=70)</i>

How can I check in code if this image item is base image (or small image, thumbnail)?

like image 910
freento Avatar asked Dec 25 '22 17:12

freento


1 Answers

Try this.

if ($item->getFile() == $product->getImage()){
    //then it's image
}

if ($item->getFile() == $product->getSmallImage()){
    //then it's small image
}

if ($item->getFile() == $product->getThumbnail()){
    //then it's thumbnail
}

Keep in mind that it can be all 3 of them.

like image 95
Marius Avatar answered Jan 06 '23 06:01

Marius