如何在Magento中弹出Ajax中显示相关产品

时间:2023-01-27 23:21:14

I'm working on an Ajax pop up that appears when Add to cart button is clicked and displays a message about the product purchased and an option to go for checkout or to continue shopping. I now am trying to enhance this by adding related products to the pop up box. Code to display image and message in pop up is as below:

我正在开发一个Ajax弹出窗口,在单击Add to cart按钮时出现,并显示有关所购买产品的消息和一个用于结帐或继续购物的选项。我现在正试图通过向弹出框中添加相关产品来增强这一点。在弹出窗口中显示图像和消息的代码如下:

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

I've added following code to display related products:

我添加了以下代码来显示相关产品:

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

Now I can See prduct placeholder image and product SKU against all related products but I can't get to show the product's small or thumbnail or original image and also the name of the item. I've used statements like htmlEscape($_item->getName()) ?> but of no use. Against each related product I want to show the product image, name, Normal and special price along with a button to add to cart. Any help would be greatly appreciated.

现在我可以看到prconduit占位符图像和产品SKU针对所有相关产品,但是我不能显示产品的小的或缩略图或原始图像以及项目的名称。我使用过htmlEscape($_item->getName()) ?针对每一个相关的产品,我想显示产品形象,名称,正常和特殊的价格以及添加到cart的按钮。如有任何帮助,我们将不胜感激。

2 个解决方案

#1


1  

Where you have this code:

这里有代码:

<?php foreach($related as $_item): ?>

Try:

试一试:

<?php foreach($related as $_item): ?>
<?php $_item = $_item->load($_item->getId()); ?>

#2


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" />

?>

#1


1  

Where you have this code:

这里有代码:

<?php foreach($related as $_item): ?>

Try:

试一试:

<?php foreach($related as $_item): ?>
<?php $_item = $_item->load($_item->getId()); ?>

#2


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" />

?>