Avian
Avian

Reputation: 69

How to display related products in Ajax pop up in Magento

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:

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

Upvotes: 2

Views: 3253

Answers (2)

Zachary Schuessler
Zachary Schuessler

Reputation: 3682

Where you have this code:

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

Try:

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

Upvotes: 1

Oğuz &#199;elikdemir
Oğuz &#199;elikdemir

Reputation: 4980

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

?>

Upvotes: 0

Related Questions