Magento Extension Needs to Override a Template

帅比萌擦擦* 提交于 2019-11-30 07:54:53

Heh, one nice thing about references is that they operate through that global space of the layout object, so you needn't do any nesting. Kudos for working this through to layout xml; it's powerful!

What you want to do, I think, is replace the default item renderer which is being set in the sales module's LXML file (see sales.xml). These are added to the block class Mage_Sales_Block_Order_Items (or sales/order_items in class group notation) via the addItemRender() method, which comes from Mage_Sales_Block_Items_Abstract. You need to replace the renderer stored in the default key of the _itemRenderers array, and you can do that simply by doing the following:

<sales_order_view>
    <reference name="order_items">
        <action method="addItemRender">
            <arg1>default</arg1>
            <arg2>groupname_extensionname/sales/order/items/renderer/default.phtml</arg2>
        </action>
    </reference>
</sales_order_view>

Let me know if this doesn't do the trick, because it shouldn't take much more beyond this.

Layout <references/> don't work like that. The outer tags (<sales_order_view/>) are called handles, and then the first level of tags inside a handle is a command that either creates, or gets a reference to a block object, and then the layer inside of that is used for calling block methods via an <action/> node. (the two exceptions are <remove/> and <update>, which are scanned for separately from the block creation process, and can be placed anywhere).

So your layout xml update will look like this.

<sales_order_view>
    <reference name="name.of.block.in.layout">
        <action method="setTemplate">                
            <template>groupname_extensionname/sales/order/items/renderer/default.phtml</template>
        </action>
    </reference>
</sales_order_view>

Some other advice to help you along the way

  1. You'll need to replace 'name.of.block.in.layout' with the name that Magento gives the block that has the sales/order/items/renderer/default.phtml template

  2. Make sure you're adding your layout xml to the ADMIN layout.

  3. Make sure you use <depends/> in app/etc/modules/Foo_Bar.xml to ensure yoru module loads after the Mage_Adminhtml module.

  4. It may be possible that Magento is generating the block you're looking for in PHP code, which means you won't be able to use the layout the way you're using it

  5. It may be simpler to look into seeing a different default admin theme for Magento (or using the find theme that ships with modern versions of Magento and is the default admin theme), and just replacing the phtml file via template hierarchies.

(Magento layouts are pretty complicated, it took me a small book to explain them.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!