在magento主题的顶栏上构建一个minicart。需要在minicart中显示产品缩略图和名称。我在目录“checkout / cart”中创建了一个top_cart.phtml文件。使用下面给出的代码。
<?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。
答案 0 :(得分:4)
您需要从产品而不是购物车项目获取图片网址。请尝试以下方法:
<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() ?>" />