Desired result:
On the order success page I want to show products that are related to the ones purchased by the user.
What I did so far:
echo $this->getChildHtml('related_products_list');
in checkout/success.phtml
class Namespace_CustomersBought_Block_Product_List extends Mage_Catalog_Block_Product_List {
protected function _construct() {
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
// some more code to get the products I need in $relatedProducts
$this->setCollection($relatedProducts);
}
}
added in my custom.xml
the following (paths are correct):
<checkout_onepage_success>
<reference name="content">
<block type="namespace_customersbought/product_list" name="related_products_list"
template="module/product/related_list.phtml" after="-">
</block>
</reference>
</checkout_onepage_success>
Where it stopped working
It renders the div I added in checkout/success.phtml
, but the getChildHtml()
call is empty.
Also, I use Magneto Debug
- and the layout update contains my XML.
What I need help with
I would like to understand why this is not working. If I replace <checkout_onepage_success>
with <cms_index_index>
I get the desired block on the homepage (without having getChildHtml()
), so why do they have different behavior?
Also - ideally I wouldn't need to modify the checkout/success.phtml
file, it should be output automatically.
I know I'm missing something very simple, but I can't figure out what.
Thank you.
I guess, there is a problem with the line
<reference name="content">
This sets your block a child to the content block. You, however have added the output to the checkout/success.phtml
template, which belongs to the block checkout.success
. I suggest you replace the xml update with the following
<checkout_onepage_success>
<reference name="checkout.success">
<block type="namespace_customersbought/product_list" name="related_products_list"
template="module/product/related_list.phtml" after="-">
</block>
</reference>
</checkout_onepage_success>