Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

I want to display products image in the compare sidebar.I don’t know how? Does anyone help me ? 
 
iceman1983
Jr. Member
 
Total Posts:  4
Joined:  2011-04-05
 

I use $this->helper(’catalog/image’)->init($_item, ‘image’); But it always return me the default image of magento ,I don’t know what’wrong with it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
aprudnikovas
Member
 
Avatar
Total Posts:  61
Joined:  2011-04-18
Ireland
 
iceman1983 - 18 May 2011 09:06 PM

I use $this->helper(’catalog/image’)->init($_item, ‘image’); But it always return me the default image of magento ,I don’t know what’wrong with it.

Well well well I just found one place http://felix.moches.de/en/magento-2/magento-snippet-preview-images-in-compare-sidebar/ but it was unavailable..except that google cached site previously and there was that code smile
into catalog/product/compare/sidebar.phtml

<ol id="compare-items">
            
<?php foreach($this->helper('catalog/product_compare')->getItemCollection() as $_index=>$_item): ?>
            
<li class="item">
            <
input type="hidden" value="<?php echo $_item->getId() ?>" />
            <
class="product-image" href="<?php echo $_item->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init(Mage::getModel('catalog/product')->load($_item->getId()), 'small_image')->resize(100, 100) ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" height="100" width="100" /></a>
                <
a href="<?php echo $_helper->getRemoveUrl($_item) ?>" title="<?php echo $this->__('Remove This Item') ?>" class="btn-remove" onclick="return confirm('<?php echo $this->__('Are you sure you would like to remove this item from the compare products?') ?>');"><?php echo $this->__('Remove This Item'?></a>
                <
class="product-name"><a href="<?php echo $this->getProductUrl($_item) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_item$_item->getName(), 'name'?></a></p>
            </
li>
            
<?php endforeach; ?>
        
</ol>
 
Magento Community Magento Community
Magento Community
Magento Community
 
magestore
Mentor
 
Avatar
Total Posts:  1015
Joined:  2009-08-07
Viet Nam
 

Hi iceman1983,

In your code, you need to change

$this->helper(’catalog/image’)->init($_item‘image’)
to
$this->helper('catalog/image')->init(Mage::getModel('catalog/product')->load($_item->getId()),'small_image')->resize(100100);

Because in this case, $_item is not really an catalog/product object, so you need to use Mage::getModel(’catalog/product’)->load() to get the object type exactly

Wish you success,
Magestore.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ashokkarthick
Jr. Member
 
Total Posts:  1
Joined:  2012-12-11
 

Thanks it really helped me

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top