Magento 1.9销售订单视图的简单按钮


Simple Button to Magento 1.9 sales order view

我试图在Magento订单中添加一个简单的按钮。我尝试了stackoverflow的解决方案,但不起作用。这是我的代码,如果你能告诉我我做错了什么,那就太好了。非常感谢。

app/local/FirstGood/PrintCard/Block/Adminhtml/Sales/Order/View.php

<?
class FirstGood_PrintCard_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');
    }
}

app/local/FirstGood/PrintCard/etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
        <FirstGood_PrintCard>
            <version>0.0.1</version>
        </FirstGood_PrintCard>
    </modules>
<global>
    <blocks>
         <adminhtml>
            <rewrite>
                <sales_order_view>FirstGood_PrintCard_Block_Adminhtml_Sales_Order_View</sales_order_view>
            </rewrite>
			<events>
        <adminhtml_widget_container_html_before>
            <observers>
                <firstgood_printcard>
                    <class>firstgood_printcard/observer</class>
                    <type>singleton</type>
                    <method>adminhtmlWidgetContainerHtmlBefore</method>
                </firstgood_printcard>
            </observers>
        </adminhtml_widget_container_html_before>
    </events>
        </adminhtml>
    </blocks> 
 </global>
 </config>

app/local/FirstGood/PrintCard/Model/Observer.php

<?php 
class FirstGood_PrintCard_Model_Observer {
    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'
        ));
    }
}
}

app/etc/modules/FirstGood_PrintCard.xml

<?xml version="1.0"?>
<config>
  <modules>
    <FirstGood_PrintCard>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </FirstGood_PrintCard>
  </modules>
</config>

您只需要使用"sales"助手,而不是"xxx"。使用下面的代码,它将有助于解决这个问题。

app/local/FirstGood/PrintCard/Block/Adminhtml/Sales/Order/View.php

<?
class FirstGood_PrintCard_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('sales')->__('Some action'),
        'onclick'   => 'jsfunction(this.id)',
        'class'     => 'go'
       ), 0, 100, 'header', 'header');
    }
}