Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show related products in product view page with magento?

Tags:

magento

I want to show related products in product view page after short description. I added the below code in app/design/frontend/default/your_theme/layout/catalog.xml page

<block type="catalog/product_list_related" name="catalog.product.related" as="related" template="catalog/product/list/related.phtml"/> `under <reference name="content">` section.

and comment the below code

 <reference name="right">
            <block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"/>
        </reference>

after that i made one related.phtml page and put it in app/design/frontend/default/your_theme/template/catalod/product/list/section. and call this related.phtml page in app/design/frontend/default/your_theme/template/catalod/product/view.phtml page by writing this code <?php echo $this->getChildHtml('related'); ?>.also cache is cleared.then also it is unable to call the page If anyone knows this,please help me out. Thanks!

like image 769
Prince Kumar Avatar asked Dec 09 '22 08:12

Prince Kumar


2 Answers

Hi i have custom code's to get the related products and you can add this code where you want to show the related products

<?php
foreach ($_product->getRelatedLinkCollection() as $link) {
$dats= $link->getLinkedProductId();
}
if($dats)
{
?>
<div class="block block-related">
<div class="block-title">
<strong><span><?php echo $this->__('Related Products') ?></span></strong>
</div>
<div class="block-content">
<ol class="mini-products-list" id="block-related">
<?php $bk=1;
foreach ($_product->getRelatedLinkCollection() as $link) {
if($bk=='4'){ break; }
else{
$relatedData[$link->getLinkedProductId()]['position'] = $link->getPosition();
$itsProducts[] = $link->getLinkedProductId();

$model = Mage::getModel('catalog/product') ;//getting product model

$_product = $model->load($link->getLinkedProductId()); 
//getting product object for particular product id

//echo $_product->getShortDescription(); //product's short description
//echo $_product->getDescription(); // product's long description
//echo $_product->getName(); //product name
//echo $_product->getPrice(); //product's regular Price
//echo $_product->getSpecialPrice(); //product's special Price
//echo $_product->getProductUrl(); //product url
//echo $_product->getImageUrl(); //product's image url
//echo $_product->getSmallImageUrl(); //product's small image url
//echo $_product->getThumbnailUrl(); //product's thumbnail image url  ?>

<li class="item">
<div class="product">
<a href="<?php echo $_product->getProductUrl(); ?>">
<img src="<?php echo $_product->getImageUrl(); ?>"
width="110" height="110" alt="1"/>    </a>
<div class="product-details">
<h2 class="product-name-related">
<a title="<?php echo $_product->getName(); ?>"href="
<?php echo  $_product->getProductUrl(); ?>">
<?php echo $_product->getName(); ?></a><div class="price-box">
<?php echo '$'.number_format($_product->getPrice(),2); ?></div></h2>
<button class="button btn-cart" onclick="setLocation('
<?php echo  Mage::helper('checkout/cart')->getAddUrl($_product); ?>')"
title="Add to  Cart" type="button"><span><span>Add to Cart</span></span></button>
</div>
</div>
</li>
<?php
$bk++;
}
}    
?>
</ol>
</div>
</div>
<?php
}
?>
like image 99
am_skp Avatar answered Jun 04 '23 16:06

am_skp


Remove the reference to the block related_products from view.phtml

<?php //echo $this->getChildHtml('related_products') ?>

Then add this to anywhere you want in view.phtml

<?php echo $this->getBlockHtml('catalog.product.related'); ?>
like image 25
Ben Incani Avatar answered Jun 04 '23 15:06

Ben Incani