How to show related products on the product view page using magento?

I want to show related products on the product review page after a brief description. I added the code below: app / design / frontend / default / your_theme / layout / catalog.xml

<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 on the code below

 <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 linked .phtml page and put it in a section app/design/frontend/default/your_theme/template/catalod/product/list/. and call this related.phtml page on the page app/design/frontend/default/your_theme/template/catalod/product/view.phtmlby writing this code <?php echo $this->getChildHtml('related'); ?>. Also the cache is cleared. In addition, he cannot call the page. If anyone knows, please help me. Thank!

+4
source share
4 answers

, , , .

<?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 short description
//echo $_product->getDescription(); // product long description
//echo $_product->getName(); //product name
//echo $_product->getPrice(); //product regular Price
//echo $_product->getSpecialPrice(); //product special Price
//echo $_product->getProductUrl(); //product url
//echo $_product->getImageUrl(); //product image url
//echo $_product->getSmallImageUrl(); //product small image url
//echo $_product->getThumbnailUrl(); //product 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
}
?>
+7

<block type="catalog/product_list_related" name="catalog.product.related" as="related" template="catalog/product/list/related.phtml"/>

<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">

catalog.xml

<reference name="content">
            <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
                <block type="catalog/product_list_related" name="catalog.product.related" as="related" template="catalog/product/list/related.phtml"/>

. ,

. catalog.xml, local.xml app/design/frontend/your_package/your_theme/layout ,

<catalog_product_view>
    <reference name="product.info">
        <block type="catalog/product_list_related" name="catalog.product.related" as="related" template="catalog/product/list/related.phtml"/>
    </reference>
    <reference name="right">
        <remove name="catalog.product.related"/>
    </reference>
</catalog_product_view>

, local.xml

+2

_ view.phtml

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

view.phtml

<?php echo $this->getBlockHtml('catalog.product.related'); ?>
+2

, .

<catalog_product_view>
    <remove name="catalog.product.related" />
    <reference name="product.info">
        <block type="catalog/product_list_related" name="catalog.product.related" as="related" template="catalog/product/list/related.phtml"/>
    </reference>
</catalog_product_view>

then in view.phtml call this

<?php
echo $this->getLayout()->getBlock(‘catalog.product.related’)->toHtml()
?>
0
source

Source: https://habr.com/ru/post/1538701/


All Articles