3

I want the product image type in galley object. Currently I'm getting the product images gallery as below. (Assume $id is the product ID)

$gallery= Mage::getModel('catalog/product')->load($id)->getMediaGalleryImages(); 

But If I Mage::log() any object in the $gallery collection it is like below.

[_data:protected] => Array ( [value_id] => 4 [file] => /p/e/penguins_1.jpg [product_id] => 4 [label] => [position] => 1 [disabled] => 0 [label_default] => [position_default] => 1 [disabled_default] => 0 [url] => http://xxxxxxxxxxxxxxxxxxx/media/catalog/product/p/e/penguins_1.jpg [id] => 4 [path] => C:\xxxxxxxxxxxxxxxxxxxxxxxxxxxx\media\catalog\product\p\e\penguins_1.jpg ) 

What I want is to get the image type in above object. Because getMediaGalleryImages() doesn't return collection with the image type.

Image type can be 'image', 'small_image' or 'thumbnail'

Any suggestion, how can I get the image type?

1
  • i am stuck on the same problem, did you find a solution in the end? Commented Sep 15, 2015 at 14:18

4 Answers 4

1

I am not sure how to get this information from the media gallery information but the thumbnail, small_image and image are simply eav_attributes.

You can find the value with the following sql where entity_type_id 4 is the product entity id.

SELECT * FROM `eav_attribute` where entity_type_id = 4 and attribute_code in ("thumbnail", "small_image", "image") 

Now what you could do is to build a collection based on product and the attributes returned from the above sql.

1
  • do you have any php code that does the same? Commented Sep 15, 2015 at 14:20
0

First of all, make sure you're not killing your performance.

Secondly, the catalog module has various helpers to aid in front-end formatting, most notably the output helper and it's productAttribute method. Make sure you're not trying to code something that's already in there.

And finally if you still need access to that information, do look at the method's implementation to see how to obtain a product attribute and information about that attribute.

1
  • 1
    Thanks for the response. But this doesn't make sense. Commented Apr 29, 2015 at 0:13
0

Not sure how to add image type to existing Media Gallery object, but if you're looking to hide custom image from media gallery use below,

Under app/design/frontend/{package}/{theme}/template/catalog/product/view/media.phtml 

Find

<?php if ($this->isGalleryImageVisible($_image)): ?> 

Replace with

<?php if ($this->isGalleryImageVisible($_image) && ($_product->getSizeGuide() != $_image->getFile())): ?> 

I've considered custom image attribute as size_guide. So replace it according to your custom image attribute.

-1

You just need to rewrite Mage_Catalog_Model_Product::getMediaGalleryImages. Inside of the foreach loop of the rewrite, insert this piece.

$image['type_code'] = exif_imagetype($image['path']); 

It will become available in the collection of images just like the other data (url, id, etc.).

To see what each type_code corresponds to, see http://php.net/manual/en/function.exif-imagetype.php.

2
  • Here the images type are 'image', 'small_image', 'thumbnail'. Not the data type Commented Apr 29, 2015 at 0:11
  • Oops, I must be having a long day. I'll look to update this at a later time.. Commented Apr 29, 2015 at 0:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.