2

I have recently started learning magento and would appreciate if anyone could explain what this does, especially the method addItemRender.

<adminhtml_sales_order_view>
 <block type="adminhtml/sales_order_view_items" name="order_items" template="sales/order/view/items.phtml">

                        <action method="addItemRender"><type>default</type><block>adminhtml/sales_order_view_items_renderer_default</block><template>sales/order/view/items/renderer/default.phtml</template></action>

                    </block>
</adminhtml_sales_order_view>

I do understand that it calls the method addItemRender with params $type, $block, $template on the block adminhtml/sales_order_view_items, but what I dont understand is what happens next and is it the same as below and calling getChildHtml() in the parent phtml ?

    <adminhtml_sales_order_view>
     <block type="adminhtml/sales_order_view_items" name="order_items" template="sales/order/view/items.phtml">

<block type="adminhtml/sales_order_view_items_renderer_default" name="order_items" template="sales/order/view/items/renderer/default.phtml"/>


                    </block>
</adminhtml_sales_order_view>

Any help would be really appreciated

5

Each order idem has a product associated to it, because that's what you buy...products.
And each product can have a different type: simple, configurable, grouped, bundle, downloadable, virtual.
Each product type may behave differently in certain conditions. For example the price should be shown differently depending on the product type.
The method addItemRenderer provides a block and a template for different product types.
To show a line in an order for a product the method Mage_Adminhtml_Block_Sales_Items_Abstract::getItemHtml is called.
This method checks the product type and looks in the associated renderers for a block and template to use.

public function getItemHtml(Varien_Object $item)
{
    if ($item->getOrderItem()) {
        $type = $item->getOrderItem()->getProductType();
    } else {
        $type = $item->getProductType();
    }

    return $this->getItemRenderer($type)
        ->setItem($item)
        ->setCanEditQty($this->canEditQty())
        ->toHtml();
}

This method calls getItemRenderer that looks if there is a block and a template associated to the product type. If there is it uses them. If not it uses the block and template marked as default.

The method is somehow similar to adding a child block to a parent block, but it's some kind of conditional child block. You have have multiple renderers associated to the parent block, but only one is used depending on what you are printing. And the renderer can be used multiple times. Each time a product of the same tipe is shown, the associated renderer is used.

  • Hi Marius, Thanks a lot. It's so much clearer to me now. Thanks again for the awesome reply. – user3726629 Nov 7 '14 at 14:22
  • @user3726629. Welcome to SE. If one answer solves your problem you should mark it as accepted. This way we keep this website clean. – Marius Nov 7 '14 at 14:25

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.