Magento 1.9 – Add Custom Block Layout to Product Page in Add to Cart Area

layoutmagento-1.9productsxml

After struggling the whole week to create an simple extension for a project of mine, I thought I finished and covered everything. Turns out I was wrong. The thing that I cannot make it work properly is related to the frontend layout. I wanted to add a custom block to the layout inside the "add to cart" area. In order to do this I added the following xml code inside my extension's layout file (after searching docs and testing an entire day):

<layout>
    <catalog_product_view>    
        <reference name="product.info.options.wrapper.bottom">
                <block type="catalog/product_view" name="my.foobar" before="addtocart" template="catalog/product/view/foobar.phtml"/>
                <action method="append">
                        <block>my.foobar</block>
                </action>
        </reference>
    </catalog_product_view>    
</layout>

I thought this was it. That this will add my block to all products above the "add to cart" button area. As you can see I used "product.info.options.wrapper.bottom" as reference. The block appeared where I wanted to, I was happy. My mistake was that I tested on a product page of a configurable product. Today I saw that the "product.info.options.wrapper.bottom" block is not visible on all types of products, making my block to also not be displayed on all products, for instance on a simple product page (unfortunately). I tried different other blocks as a reference, but everything was in vain. I don't know why the original layout puts the "add to cart" container in different parts of the product sidebar. This causes my layout change not to work for all types of products.

Right now I don't know what to add/modify. Can anyone help me with this ?

edit: Here is an image to better reflect the area where I want my block to be positioned

enter image description here

Best Answer

I guess it depends on what your trying to add and if it needs to be at a particular point e.g before or after the add to cart button.

If after the addtocart button is ok you can use product.info.addtocart since it calls <?php echo $this->getChildHtml('', true, true) ?>.

e.g

<catalog_product_view>
    <reference name="product.info.addtocart">
        <block type="core/text" name="core-text"><action method="setText"><text><![CDATA[<div>Test</div>]]></text></action></block>
    </reference>
</catalog_product_view>

Update: If you wrap the text in a div as I have updated above it will work in the default theme like below. But this may not work quite right in other themes like the new rwd.

enter image description here

Related Topic