I’m building an extension to add a specific block right before the ‘Place Order’ button in Magento’s Onepage checkout. I’m having some trouble finding the right incantations to simply append a block to this section, much less get it before/after another handle. The object is to engage this override without any template changes.
In my extension’s XML, I have:
<checkout_onepage_review>
<reference name="root">
<block type="myextension/blockname" name="myextension.block" template="myextension/block.phtml" before="checkout.onepage.review.button" />
</reference>
</checkout_onepage_review>
myextension/block.phtml is, for now, just a simple block of text. I know the general syntax is correct, as I’m able to add my <block> to checkout_cart_index and see it just fine.
Am I missing something basic?
Thanks!
Background
Not all blocks output their children blocks automatically. Only blocks of the
core/text_listtype and templates whereecho $this->getChildHtml()(no arguments) s called.Children of template blocks are rendered by a call to
echo $this->getChildHtml('child_alias').It makes sense if you think about it – children of template blocks need to be positioned somewhere in the context of the template HTML.
Referring to your question, there is no functional difference between the layout handles
checkout_onepage_reviewandcheckout_cart_indexbesides them referring to different pages.Adding content to the checkout review
The checkout review block contains two
core/text_listchildren to whom you can add children using layout XML that will automatically be displayed.The only problem is that the
checkout.onepage.review.info.items.afterblock is rendered before the agreements block, so in your case it might not be good enough.The agreements are rendered with this code:
If you want to add a block after the agreements, right before the “Place Order” button, without changing the template, and without rewriting the agreements block, you can try to add an additional item to the end of the
checkout/agreementscollection, havingis_htmlset to true, and your output as thecontent.This turns out to be problematic, though, because the agreements model, resource, and collection don’t offer a custom event prefix.
What this boils down to, if the provided
checkout.onepage.review.info.items.afterblock doesn’t work, are the following options. Each one is ugly in it’s own way, so the choice of the smallest evil is yours:core_block_abstract_to_html_beforementioned in the post linked to in the commentscore_collection_abstract_load_beforeevent and add a html agreement on the flycheckout/agreementsblock and overload the_toHtml()methodMy recommendation would be to somehow make use of the
checkout.onepage.review.info.items.afterblock – that solution would be so much nicer.