0

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:

  • product attribute that contains related products
  • added echo $this->getChildHtml('related_products_list'); in checkout/success.phtml
  • block that extends the product_list, and sets the appropriate collection (note: this is not a rewrite)

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.

Vlad Preda
  • 9,780
  • 7
  • 36
  • 63

1 Answers1

2

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>
Oleg Ishenko
  • 2,243
  • 1
  • 15
  • 16