![](/img/trans.png)
[英]Add new button for custom made order status to order view in Magento admin panel?
[英]How to add new button to order view in Magento admin panel?
如何在“返回”和“編輯”附近的訂單視圖頁面中添加自定義按鈕?
無需核心黑客或重寫,只需使用觀察者將按鈕添加到訂單中:
<adminhtml>
<events>
<adminhtml_widget_container_html_before>
<observers>
<your_module>
<class>your_module/observer</class>
<type>singleton</type>
<method>adminhtmlWidgetContainerHtmlBefore</method>
</your_module>
</observers>
</adminhtml_widget_container_html_before>
</events>
</adminhtml>
然后只需檢查觀察者塊的類型是否與訂單視圖匹配:
public function adminhtmlWidgetContainerHtmlBefore($event)
{
$block = $event->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
$message = Mage::helper('your_module')->__('Are you sure you want to do this?');
$block->addButton('do_something_crazy', array(
'label' => Mage::helper('your_module')->__('Export Order'),
'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('*/yourmodule/crazy')}')",
'class' => 'go'
));
}
}
塊的“getUrl”function 將自動 append 將當前訂單 id 傳遞給 controller 調用。
config.xml:
<global>
<blocks>
<adminhtml>
<rewrite>
<sales_order_view>Namespace_Module_Block_Adminhtml_Sales_Order_View</sales_order_view>
</rewrite>
</adminhtml>
</blocks>
</global>
命名空間/模塊/塊/Adminhtml/Sales/Order/View.php:
class Namespace_Module_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
public function __construct() {
parent::__construct();
$this->_addButton('button_id', array(
'label' => Mage::helper('xxx')->__('Some action'),
'onclick' => 'jsfunction(this.id)',
'class' => 'go'
), 0, 100, 'header', 'header');
}
}
參考上面關於 parent::__constructor 的評論,這對我有用:
class Name_Module_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
public function __construct() {
$this->_addButton('testbutton', array(
'label' => Mage::helper('Sales')->__('Toms Button'),
'onclick' => 'jsfunction(this.id)',
'class' => 'go'
), 0, 100, 'header', 'header');
parent::__construct();
}
}
如果您想快速而簡單地進行操作(即編輯核心文件),請打開app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
並添加以下內容:
$this->_addButton('order_reorder', array(
'label' => Mage::helper('sales')->__('Print Labels'),
'onclick' => 'window.open(\'/printouts/' . $this->getOrder()->getRealOrderId() . '.pdf\')',
));
您可以將其放在此塊之前:
if ($this->_isAllowedAction('emails') && !$order->isCanceled()) {
$message = Mage::helper('sales')->__('Are you sure you want to send order email to customer?');
$this->addButton('send_notification', array(
'label' => Mage::helper('sales')->__('Send Email'),
'onclick' => "confirmSetLocation('{$message}', '{$this->getEmailUrl()}')",
));
}
如果您選擇接受,您的挑戰是在本地創建一個替代核心文件的文件,並將其發布在這里!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.