1

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?

crowjonah
  • 2,858
  • 1
  • 23
  • 27
Linkjuice57
  • 3,473
  • 6
  • 24
  • 23
  • See http://stackoverflow.com/questions/8288340/get-original-image-url-magento-1-6-1-0/8288805#8288805 – benmarks Sep 17 '12 at 17:02

2 Answers2

9

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!

Community
  • 1
  • 1
Abid Hussain
  • 7,724
  • 3
  • 35
  • 53
  • Wow, what a great answer... :-) – benmarks Sep 17 '12 at 17:01
  • Problem is that I get the exact same image when I echo `Image` `Thumbnail` or `SmallImage`. Is this then just a problem with my store? – Linkjuice57 Sep 18 '12 at 12:18
  • See below URL it is help full. http://stackoverflow.com/questions/2474117/how-to-get-a-products-image-in-magento – Abid Hussain Sep 18 '12 at 18:11
  • I have update my answer after you above comment. please take a look. And see also this url http://stackoverflow.com/questions/4349592/make-all-store-images-the-base-small-and-thumbnail-images-in-magento – Abid Hussain Sep 18 '12 at 18:16
2

If you want to see which data you can access you could try this:

<?php var_dump(array_keys($product->getData())); ?>

You can then use two methods to get this data:

<?php $product->getAttributeName() // Use CamcelCase ?>

or

<?php $product->getData('attribute_name') // underscores ?>
Andrew
  • 12,617
  • 1
  • 34
  • 48