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

时间:2016-01-02 10:09:19

标签: php magento

我试图在Magento Order中添加一个简单的按钮。我尝试了stackoverflow的解决方案,但它无法正常工作。这是我的代码,如果你能告诉我我做错了什么会很棒。谢谢。

应用程序/本地/ FirstGood / PrintCard /砌块/ Adminhtml /销售/订购/ 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');
    }
}

应用程序/本地/ 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>

应用程序/本地/ FirstGood / PrintCard /型号/ 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'
        ));
    }
}
}

应用程序的/ etc /模块/ 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>

1 个答案:

答案 0 :(得分:0)

你只需要使用&#34;销售&#34;助手,而不是&#34; xxx&#34;。使用下面的代码,它将有助于解决这个问题。

应用程序/本地/ FirstGood / PrintCard /砌块/ Adminhtml /销售/订购/ 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');
    }
}
相关问题