Magento 1.9 – Moving a Block to a Different Block

blockslayoutmagento-1.9productxml

I'm using a module of Amasty that adds a block to my catalog product view's content reference. This puts in on the top of the page, but I want to move it just above the upsell in the product.info block.

I'm trying to unset this using unsetChild and inserting it just above product.info.upsell, but I can't get it to work. The block keeps appearing above the whole product.info block or below it.

This is my code:

<catalog_product_view>
        <reference name="content">
            <action method="unsetChild"><name>amprevnext_prevnext</name></action>
            <action method="insert">
                <blockName>amprevnext_prevnext</blockName>
                <siblingName>product.info.upsell</siblingName>
                <after>0</after>
            </action>
        </reference>
    </catalog_product_view>

How do I do this?

Best Answer

It is because the awprevnext_prevnext is added to the content block and not to the product.info block.

Here's what you should do:

<catalog_product_view>
    <reference name="content">
        <action method="unsetChild"><name>amprevnext_prevnext</name></action>
    </reference>
    <reference name="product.info">
        <action method="insert"><block>amprevnext_prevnext</block></action>
    </reference>
</catalog_product_view>

However, this won't be enough because the product.info original template catalog/product/view.phtml does not render all the child block automatically by calling echo $this->getChildHtml();

Thus you need to add the following to your custom theme catalog/product/view.phtml template:

<?php echo $this->getChildHtml('amprevnext_prevnext'); ?>

You need to add that code before the following code:

<?php echo $this->getChildHtml('upsell_products') ?>
Related Topic