Magento 1.7 Thumbnail Image not Displaying

2019-09-01 01:39发布

问题:

Building a minicart on top bar in magento theme. Need to show products thumbnail and name in minicart. I have made a file top_cart.phtml in directory "checkout/cart". Using the code given below.

<?php 

$_cartQty = $this->getSummaryCount();
$session = Mage::getSingleton('checkout/session');
if ($_cartQty == 0) : ?>
    <span class="titleBlock">Your shopping cart is empty.</span>
<?php else : 
    foreach($session->getQuote()->getAllItems() as $_item): ?>
    <div>
        <span><?php echo $_item->getThumbnailImage(); ?></span>
        <span><?php echo $_item->getName(); ?></span>
    </div>
    <?php endforeach ?>
<?php endif;?>  
?>

Now the name is shown correctly but the thumbnail images are not being shown. Guide plz.

回答1:

You need to get the image url from the product and not the cart item. Try the following:

<img src="<?php echo $_item->getProduct()->getThumbnailUrl() ?>" alt="<?php echo $_item->getName() ?>" />

Or if you are going to be resizing the image or doing anything else with it then use the catalog/image helper. Here is an example of getting the image and resizing it:

<img src="<?php echo $this->helper('catalog/image')->init($_item->getProduct(), 'thumbnail')->resize(50); ?>" alt="<?php echo $_item->getName() ?>" />


标签: magento