I'm trying to add custom block to the order view in Magento admin. I have followed this tutorial but it doesn't seem to work.
app/etc/modules/Webspeaks_MyModule.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Webspeaks_MyModule>
<active>true</active>
<codePool>local</codePool>
</Webspeaks_MyModule>
</modules>
</config>
app/code/local/Webspeaks/MyModule/etc/config.xml
<?xml version="1.0"?>
<config>
<adminhtml>
<layout>
<updates>
<webspeaks_mymodule>
<file>mymodule.xml</file>
</webspeaks_mymodule>
</updates>
</layout>
<events>
<core_block_abstract_to_html_after>
<observers>
<mymodule_custom_order_view_info>
<class>mymodule/observer</class>
<method>getSalesOrderViewInfo</method>
</mymodule_custom_order_view_info>
</observers>
</core_block_abstract_to_html_after>
</events>
</adminhtml>
</config>
app/code/local/Webspeaks/MyModule/Model/Observer.php
<?php
class Webspeaks_MyModule_Model_Observer {
// This function is called on core_block_abstract_to_html_after event
// We will append our block to the html
public function getSalesOrderViewInfo(Varien_Event_Observer $observer) {
$block = $observer->getBlock();
// layout name should be same as used in app/design/adminhtml/default/default/layout/mymodule.xml
if (($block->getNameInLayout() == 'order_info') && ($child = $block->getChild('mymodule.order.info.custom.block'))) {
$transport = $observer->getTransport();
if ($transport) {
$html = $transport->getHtml();
$html .= $child->toHtml();
$transport->setHtml($html);
}
}
}
}
app/design/adminhtml/default/default/layout/mymodule.xml
<?xml version="1.0"?>
<layout version="1.0">
<!-- Adding the block in sales/order/view page -->
<adminhtml_sales_order_view>
<!-- You can change the reference to whatever you like. Look ate layout/sales.xml for more options -->
<!-- This should be same in Model/Observer.php::getSalesOrderViewInfo() -->
<reference name="order_info">
<block type="mymodule/adminhtml_sales_order_view_info_block" name="mymodule.order.info.custom.block" template="mymodule/custom.phtml" before="order_history" />
</reference>
</adminhtml_sales_order_view>
</layout>
app/design/adminhtml/default/default/template/mymodule/custom.phtml
<?php $order = $this->getOrder() ?>
<div class="entry-edit box-left">
<div class="entry-edit-head">
<h4 class="icon-head"><?php echo $this->__('My Custom Block') ?></h4>
</div>
<fieldset>
<div id="mymodule_custom_block">
Special message
</div>
</fieldset>
</div>
<div class="clear"></div>
app\code\local\Webspeaks\MyModule\Block\Adminhtml\Sales\Order\View\Info\Block.php
<?php
class Webspeaks_MyModule_Block_Adminhtml_Sales_Order_View_Info_Block extends Mage_Core_Block_Template {
protected $order;
public function getOrder() {
if (is_null($this->order)) {
if (Mage::registry('current_order')) {
$order = Mage::registry('current_order');
}
elseif (Mage::registry('order')) {
$order = Mage::registry('order');
}
else {
$order = new Varien_Object();
}
$this->order = $order;
}
return $this->order;
}
}