Drmjo
Drmjo

Reputation: 584

Magento original image resize only shows placeholder image

I am trying to get this piece of code to work in magento 1.7.0...

it only displays the magento placeholder image...

if i change "image" to "small_image" it works fine

everything is set up in the back end the radio buttons are selected for the product images... I have cleared the cache also...

this is happening in the list.phtml file ...

can someone kind enough tell me what i am doing wrong or WHY its not working... i have been searching all over i found one solution after 3 days of searching and it didn't work....

$_item is not defined so a i get a call to a non object error...

here's a link to the answere

Get base product image in Magento

<?php echo $this->helper('catalog/image')->init($_product, 'image')->resize(171, 259);

Upvotes: 3

Views: 10639

Answers (5)

Stefan
Stefan

Reputation: 9234

Check if the collection did load the image attribute:

$productId = 1234;
$product = Mage::getModel('catalog/product')
    ->load($productId);
echo (string)Mage::helper('catalog/image')->init($product, 'image')->resize(75, 75);
echo (string)Mage::helper('catalog/image')->init($product, 'small_image')->resize(75, 75);
echo (string)Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75);

if this gives you only some kind of placeholder the collection didn't load the image.

You can either extend your collection like

$collection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect('small_image') //or
        ->addAttributeToSelect('thumbnail')  //or
        ->addAttributeToSelect('image');

or work with the media config instead:

$prodImage = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getThumbnail());

or use

$prodImage = Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'image', Mage::app()->getStore());

FLAT TABLES

It might be caused by the flat tables. Check if you have flat tables enabled:

System > Configuration > Catalog > Catalog > Frontend > Use Flat Catalog Product

If yes, check if the flat tables contain the image attribute:

describe catalog_product_flat_1; // number varies depending on store

If the image attribute is not part of the flat tables, just add it to the table by adding following code to app/etc/config.xml

<config>
    <frontend>
        <product>
            <collection>
                <attributes>
                    <image />
               </attributes>
            </collection>
        </product>
    </frontend>
</config>

Upvotes: 0

Waqleh
Waqleh

Reputation: 10151

I got it fixed after I read what @Meyer said. Make sure that that developer mode is set to false this can be done from the root .htaccess file by setting this to the end of the file:

SetEnv MAGE_IS_DEVELOPER_MODE "true"

and what this will do is set:

Mage::setIsDeveloperMode(true); to Mage::setIsDeveloperMode(false); in the index.php file

Upvotes: 0

Frank
Frank

Reputation: 530

Since this thread comes up in Google first, I put my experience here. The above solution does not work for the view.phtml/media.phtml templates. There the attributes have already been loaded. In my case it didn't work because the memory limit of the server wasn't sufficient for the image resizing process. It did work for the default media template (resize(56)) since it uses default sizes which have already been generated. I added `ini_set('memory_limit', '1024M')' to my index.php to fix it.

I didn't think of it right away since my php.ini is already set to 1024M. Magento overrides it in .htaccess (php value memory_limit -1) which somehow does not work for my configuration.

Upvotes: 1

Meyer
Meyer

Reputation: 29

there is something I didn't find in forums. So I share my solution about the problem, you have to change:
Mage::setIsDeveloperMode(true); to Mage::setIsDeveloperMode(false);

Upvotes: 1

redjam13
redjam13

Reputation: 1016

I would try either...

a) Adding addAttributeToSelect('image') to the product collection in your List Block (assuming it's local).

...or... (Warning: this is hacky and not best practice)

b) In your list.phtml file, load the full product from the product ID you already have

$productId = $_product->getId();
$_product = Mage::getModel('catalog/product')->load($productId);
echo $this->helper('catalog/image')->init($_product, 'image')->resize(171, 259);

Upvotes: 8

Related Questions