Frage

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?

War es hilfreich?

Lösung

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!

Andere Tipps

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 ?>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top