I've multiple sidebars on my website.

1 of them is showing images correctly. But the last one (recently ordered products) is only showing the default magento placeholder.


enter image description here

Here is the code used in the sidebar.phtml to retrieve the image:

<a href="<?php echo $_item->getProduct()->getProductUrl() ?>"><?php echo $this->escapeHtml($_item->getName()) ?>
        style="width: 50px; float: right; border: 1px solid lightgray; border-radius: 6px; padding: 5px; margin-right: 5px;"
        src="<?php $_product = $_item->getProduct();
        echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(50, 50); ?>"/>

How can I retrieve the actual product image (thumbnail) instead of the magento default placeholder?

I already tried this solution, but this ain't working for me.


Can you please try this:

Replace the code inside "src" attribute in your image for this one:

$_product = Mage::getModel('catalog/product')->load($_item->getId());
echo Mage::helper('catalog/image')->init($_product, 'thumbnail');

In order for you to get the thumbnail, I think, you need to load the product and $_item->getProduct() is not enough for that so simply change that to:


and you should be good to go.

Let me know if it worked!

  • You welcome @Mand, glad I could help! – Paul Jun 30 '16 at 9:23
  • In your code not get product data bcz your load item id <?php $_product = Mage::getModel('catalog/product')->load($_item->getId());?> – Abdul Jun 30 '16 at 9:48
  • Yor must be load <?php $_product = Mage::getModel('catalog/product')->load($_item->getProductId());?> – Abdul Jun 30 '16 at 9:48
  • @Abdul That does not work exactly like that, everything depends on how the $_item was defined, if it was inside a foreach for instance it can be retrieved in multiple ways, since you have not loaded any product yet you cannot assume getProductId() is right way to go, so you can just do getId() – Paul Jun 30 '16 at 11:18

Try this:

<?php $_product = Mage::getModel('catalog/product')->load($_item->getProductId());?>
<a href="<?php echo $_item->getProduct()->getProductUrl() ?>"><?php echo $this->escapeHtml($_item->getName()) ?>
    <img src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail');  ?>"/>


<?php $_product = $_item->getProduct();?>
<a href="<?php echo $_item->getProduct()->getProductUrl() ?>"><?php echo $this->escapeHtml($_item->getName()) ?>
    <img src="<?php echo Mage::helper('catalog/image')->init($_product, 'image');  ?>"/>   
  • Thanks for your reply! your first solution gives me a "failed to open file error" And your other solution also gives me a placeholder. – Mand Jun 30 '16 at 9:21
  • 1
    updated ans pls check now – Abdul Jun 30 '16 at 9:44

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.