我正在处理单击“添加到购物车”按钮时显示的Ajax弹出窗口,并显示有关所购买产品的消息以及用于结帐或继续购物的选项。我现在正试图通过在弹出框中添加相关产品来增强此功能。 弹出窗口中显示图像和消息的代码如下:
?php
$product = Mage::getModel('catalog/product')->load($this->getRequest()->getParam('product'));
$message = $this->__('<b>%s</b> is successfully added to your Shopping Basket.', $product->getName());?>
<div id="ajax_image">
<img src='<?php echo Mage::helper('catalog/image')->init($product, 'image')->resize(60,null)?>' />
<span><?php echo $message ?></span>
</div>
<div class="row2">
<a class="back" id="closeLink" href="javascript:void(0);"><span><?php echo $this->__('Continue Shopping') ?></span></a>
<a class="next" href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK).'checkout/cart/' ?>"><span><?php echo $this->__('Checkout') ?></span></a>
</div>
我添加了以下代码来显示相关产品:
<div>
<?php $related= $product->getRelatedProducts(); ?>
<?php foreach($related as $_item): ?>
<ul class="mini-products-list" id="block-related">
<li class="item">
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
<?php if (!$_item->getRequiredOptions()): ?>
<?php endif; ?>
<?php endif; ?>
<div class="product">
<a href="<?php echo $_item->getProductUrl() ?>"><img src="<?php echo $_item->getImageUrl(); ?>" width="80" height="80" /></a>
<div class="product-details">
<p class="product-name">
<a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a></p>
<p class="sku"><?php echo $_item->getSku()?></p>
</div>
</div>
</li>
<?php endforeach ?>
</ul>
现在我可以查看针对所有相关产品的产品占位符图像和产品SKU,但我无法显示产品的小图标或缩略图或原始图像以及项目的名称。我使用过htmlEscape($ _ item-&gt; getName())等语句?&gt;但没用针对每个相关产品,我想显示产品图片,名称,正常和特价以及添加到购物车的按钮。任何帮助将不胜感激。
答案 0 :(得分:1)
你有这个代码的地方:
<?php foreach($related as $_item): ?>
尝试:
<?php foreach($related as $_item): ?>
<?php $_item = $_item->load($_item->getId()); ?>
答案 1 :(得分:0)
<?php
$product->getThumbnailUrl(); // for thumnbail image
// alternate
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(64, 64); ?>" alt="<?php echo $this->htmlEscape($product['name']); ?>" border="0" width="68" />
?>