// [...] $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.
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
With one of the highest internet penetration rates, the UAE has set out to revolutionize… Read More
Artificial Intelligence (AI) has been continually evolving, leading to remarkable advancements in various industries. Among… Read More
Extensions, extensions and lots of extensions. We all love extensions, don’t we? After all, extensions… Read More
Software quality is crucial to a firm's success across industries in the quickly changing digital… Read More