So, I switched the template of order_info to add some more information by adding a child block to it in adminhtml_sales_order_view. The order account information in the admin is updated correctly, and I see what I added.

Layout update

    <reference name="order_info">
        <!-- Replace it with my template -->
        <action method="setTemplate"><template>qwer/sales/order/view/info.phtml</template></action>
        <!-- Add a child block -->
        <block type="qwer_sales/adminhtml_sales_order_view_info_ax" name="ax_account_info" template="sdm/sales/order/view/ax.phtml" />

My custom class below has some additional methods to retrieve what I want.

class QWER_Sales_Block_Adminhtml_Sales_Order_View_Info_Ax extends Mage_Adminhtml_Block_Sales_Order_View_Info

However, when I try to toHtml() on this child block from a controller action, I get an error saying Invalid parent block for this block because getParentBlock() in _beforeToHtml() returns null. I'm actually rendering the child block using a layout update as well, but the issue comes down to this - see below.

In a controller action...

$html = $this->getLayout()

Any ideas why this is not working and what I need to do to fix it?

Update: Solved it. See my answer.


Might be the class your extending from just try

class QWER_Sales_Block_Adminhtml_Sales_Order_View_Info_Ax extends Mage_Core_Block_Template
  • maybe since your setting two templates, it is getting destroyed – cleong May 13 '15 at 15:16
  • This did give me an idea. But basically, the Ajax request did not have any data other than what was passed into it via the URL. – musicliftsme May 13 '15 at 16:27
  • cool, how did you fix it? – cleong May 13 '15 at 16:28
  • Yup, thanks for the hint! I added an answer. – musicliftsme May 13 '15 at 16:31

The answer was that the Ajax request simply did not have information of the layout. All it has is its request URL and the parameters embedded in it. I made the following changes to make the block "self-sufficient". This prevents the "invalid parent block" error.

class QWER_Sales_Block_Adminhtml_Sales_Order_View_Info_Ax extends Mage_Adminhtml_Block_Template

Additionally, I pass in the order ID to the Ajax request, which in turn initializes the order and relevant data in the controller action. So, when the block refreshes, it will have the order data required to render.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.