Magento – Related products in the addtocart.phtml

layoutproduct

I need to move the related products to

below the product options
and above the add to cart button

Is there a way to call the related products from within addtocart.phtml?

I tried moving the following out of view.phtml into addtocart.phtml but nothing shows

 if ($tmpHtml = trim($this->getChildHtml('catalog.product.related')))
     echo '<div class="box-sidebar-inner">'. $tmpHtml .'</div>';    

Can anyone help with this.

Best Answer

You should change your layout file catalog.xml:

Was:

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

Should be:

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

Your code should work then.

In case you have getChildHtml('') block you should create block in addtocart.phtml template:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>

<?php echo $this->getLayout()->createBlock('catalog/product_list_related')->setTemplate('catalog/product/list/related.phtml')->toHtml() ?>

<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>