Magento XML file with an observer to customize the backend
// [...] $this->_addButton('order_edit', array( 'label' => Mage::helper('sales')->__('Edit'), 'onclick' => $onclickJs )); // [...]Now we have identified how it’s done, we can simply add a rewrite rule to our config.xml for that very class, extend it, inherit the constructor and add a function call to create the desired custom button with a click event redirecting to our controller. It works, right? Depends. What if an already installed extension with higher priority already rewrote the Order_View block?
<events> <adminhtml_block_html_before> <observers> <domain_module_add_custom_button> <class>Domain_Module_Model_AdminhtmlBlockObserver</class> <method>addCustomButtonToOrderView</method> </domain_module_add_custom_button> </observers> </adminhtml_block_html_before> </events>In the observer itself, we only have to check whether we are dealing with our target block, all other blocks will be left untouched. Note that we are also checking whether the block in question is a subclass of our target block in case a module with a higher priority has already rewritten and extended our target class.
<?php class Domain_Module_Model_AdminhtmlBlockObserver { const TARGET_CLASS = 'Mage_Adminhtml_Block_Sales_Order_View'; public function addCustomButtonToOrderView(Varien_Event_Observer $observer) { $block = $observer->getEvent()->getBlock(); // Skip anything which isn't our target if (! (get_class($block) === self::TARGET_CLASS || is_subclass_of($block, self::TARGET_CLASS))) { return; } $block->addButton( 'some_id', array( 'label' => Mage::helper('module')->__('Custom button'), 'onclick' => 'setLocation(\'somewhere\');', 'class' => 'go' ) ); } }And with that, we have a pretty fail safe yet clean method to customize the Magento backend which doesn’t clash with other extensions.
Your greatest possible competitive advantage can be your clients and the interactions they have with… Read More
Digital marketing KPIs are measurable values that marketing teams use to track progress toward desired… Read More
In today's digital age, fraud poses a significant threat to businesses of all sizes. As… Read More
Financial crimes continue to evolve and proliferate in our increasingly digital, global economy. From complex… Read More
In the highly competitive modern workplace, trust, and employee loyalty are crucial factors for long-term… Read More
In the ever-evolving world of small business developing and implementing effective marketing strategies is critical to… Read More