2012-06-07 64 views
0

在magento主题的顶部酒吧上建立一个小型图标。需要在minicart中显示产品缩略图和名称。我在目录“checkout/cart”中创建了一个文件top_cart.phtml。使用下面给出的代码。Magento 1.7缩略图图像不显示

<?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;?> 
?> 

现在名称显示正确,但缩略图图像未显示。指南plz。

回答

4

您需要从产品中获取图像URL,而不是购物车项目。请尝试以下操作:

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

或者,如果你将要调整图像大小,或做别的事情与它然后使用目录/图像帮手。以下是获取图像并调整其大小的示例:

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