Magento: How to get thumbnail?

Linkjuice57 picture Linkjuice57 · Sep 17, 2012 · Viewed 13.7k times · Source

I downloaded a script to create a CSV datafeed of my products and I would also like to include a url to the thumbnail. The code already has the following for the product image url:

$product_data['ImageURL']=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();

So I tried to adjust this to:

$product_data['ThumbnailURL']=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getThumbnail();

Which displays exactly the same image url (not the thumb). How would I fix this?

I did a var_dump($product); and the result was:

["image"]=> string(18) "/f/i/file_2_18.png" ["small_image"]=> string(18) "/f/i/file_2_18.png" ["thumbnail"]=> string(18) "/f/i/file_2_18.png"

I also need to get the subcategory for the product but I don't know how to call this. How can I see which variables are possible? E.g. $product->getPrice or $product->getName?

Answer

Abid Hussain picture Abid Hussain · Sep 17, 2012

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

$_product->getMediaGalleryImages()->getItemByColumnValue('label', 'LABEL_NAME')->getUrl();

Or another example

You should use the catalog product media config model for this purpose.

<?php

//your code ...

echo Mage::getModel('catalog/product_media_config')
            ->getMediaUrl( $product->getImage() ); //getSmallImage(), getThumbnail()

Edit After your comment.

Update Answer

See below URL

Make all store images the base, small and thumbnail images in Magento?

Try it

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
    if (!$product->hasImage()) continue;
    if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());
    $product->save();
}

Hope that helps you!