1

This question already has an answer here:

I just want item id after every item so I could create some buttons get some information from database but it is always showing id of first item this is my xml

<layout version="0.1.0">
<adminhtml_sales_order_view>
    <reference name="order_item_extra_info">
        <block type="core/template" name="cgorder_wrap_container" template="customsales/sales/cgorder_details_container.phtml">
            <!-- Replace it with your OWN block -->
            <block type="core/template" name="own_real_block" template="customsales/sales/cgorder_details.phtml" />
        </block>
    </reference>
</adminhtml_sales_order_view>

this is my parent template file

<tr>
<td><?php echo $this->getChildHtml();?></td>
<td colspan="8"></td></tr>

this is my child template file

<?php
$id = $this->getParentBlock()->getParentBlock()->getItem()->getID();
echo "id is ".$id;
?>

enter image description here

marked as duplicate by Fabian Blechschmidt, Fabian Schmengler, Raphael at Digital Pianism, Amit Bera, Qaisar Satti Apr 18 '16 at 4:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You will have the problem with every patch still, because the patched file is not used, but yours, when you have another template file, either due to overwrite or to change. But at least you don't lose the changes :-) magento.stackexchange.com/q/79132/217 – Fabian Blechschmidt Apr 15 '16 at 11:05
0

Try to add your block as the child of the <block type="core/text_list" name="order_item_extra_info"></block>. It should look like this:

Layout:

<adminhtml_sales_order_view>
    <reference name="order_item_extra_info">
        <block type="core/template" name="own_name" template="sales/test.phtml" />
    </reference>
</adminhtml_sales_order_view>

Template sales/test.phtml (wrapper, table structure):

<tr>
    <td><?php echo $this->getParentBlock()->getItem()->getId();?></td>
    <td colspan="8"></td>
</tr>

Here result (where 807 and 809 is item ids):
Result

PS: Do not forget to save table structure in the template.

  • Thanks. I have got the HTML one more thing can you tell me how can I retrieve that item array in test2.phtml I tried $_item = $this->getItem(); but it did not work.. – Atharuddin Apr 15 '16 at 11:35
  • @Atharuddin Try something like this: $item = $this->getParentBlock()->getParentBlock()->getItem(); – Siarhey Uchukhlebau Apr 15 '16 at 11:47
  • Thank you so much. you saved me from hours of searching.... – Atharuddin Apr 15 '16 at 11:55
  • @Atharuddin you’re welcome :) – Siarhey Uchukhlebau Apr 15 '16 at 11:58
  • I just realised that it only gets one item and it is displaying info of that item repeatedly. :( – Atharuddin Apr 19 '16 at 16:49

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