2

I'm working on a loyalty module. For each order, i would like to show the number of loyalty points related to the it in the sales_order_view, just below the order_totals block, declared in the sales.xml layout.

The problem is that i can't modify or override core's templates to avoid any conflict with another module. Therefore, i can't add getChildHtml() to place my block.

Do you have any idea ?

0

You cannot do that for the block you want.
Here is why.
The template sales/order/view.phtml renders the order_items block through the line <?php echo $this->getChildHtml('order_items') ?>.
This one is rendered by the template sales/order/items.phtml.
This other one shows the order totals through <?php echo $this->getChildHtml('order_totals') ?>. the totals block is rendered by the template sales/order/totals.phtml. None of the templates mentioned above have a getChildHtml() call without any parameters nor do they allow a generic block where you can add a child block for rendering.

4
  • I noticed that. However, is it possible to use an observer on core_block_abstract_prepare_layout_before event to catch order_totals block, and then add a child to this block which i could use later in my layout ? – WilliamZ May 11 '15 at 15:12
  • I don't think that would work either. Attaching a block to the order_totals is not a problem. you can do that via layout files. The problem is displaying it. you need an event to attach some html after the main block html is generated. You can try with core_block_abstract_to_html_after but not sure that works. – Marius May 11 '15 at 15:16
  • I previously did that by editing the HTML content of the block's transportObject directly in my observer. I felt uncomfortable because it didn't respect the MVC pattern. But you gave me an idea : the HTML is now located in a template, and i load it with toHtml(). Thanks. – WilliamZ May 11 '15 at 16:23
  • There are various text lists in several blocks in a given page. One that's always there is for example before_body_end . If you can determine what to display without requiring information from a specific block, you can insert it through Javascript and the challenge is reduced to displaying it at the right spot in the page. – Melvyn May 11 '15 at 17:54

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.