0

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.

0

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; ?>
| improve this answer | |
  • That kind of works.. But the related products show underneath when i add the XML, then when i add the code in they show in the right place. But stay underneath also.. So there are 2 copies – eleven11 Oct 3 '13 at 8:37
  • Why don't use 2 items of block? You could rename it under the addtocart node. – Anthony Oct 3 '13 at 9:14
  • What i mean is the related products are showing up twice now with this method... I only want them to show once They are displaying underneath the addtocart section with the XML, then being duplicated when i add the code into addtocart.phtml.. How do i remove the ones from showing below – eleven11 Oct 3 '13 at 10:40
  • Ah, I see now. I updated my post. – Anthony Oct 3 '13 at 10:56
  • Thats great - I get how it works now.. Thanks a lot – eleven11 Oct 3 '13 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.