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?

  • i am stuck on the same problem, did you find a solution in the end? – Jimmery Sep 15 '15 at 14:18
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.

  • do you have any php code that does the same? – Jimmery Sep 15 '15 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
    Thanks for the response. But this doesn't make sense. – Sukeshini Apr 29 '15 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.

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

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.