1
我試圖添加一個簡單的按鈕到Magento訂單。我嘗試了從stackoverflow的解決方案,但它不工作。這是我的代碼,如果你能告訴我我做錯了什麼,那將是非常棒的。謝謝。簡單的按鈕到Magento 1.9銷售訂單視圖
應用程序/本地/ FirstGood/PrintCard /座/ Adminhtml /銷售/訂單/ View.php
<?
class FirstGood_PrintCard_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
public function __construct() {
\t \t 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>
\t \t \t <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>
謝謝,看來,這是一個錯誤,但它仍然是不顯示的按鈕。但我想,這是因爲其他擴展已經在這個地方添加按鈕/操作按鈕。但是,如果我改變它在覈心文件中的工作......我真的沒有得到它如何簡單的事情再次不與magento工作。 – user3768823
更改核心文件不是一個好主意,儘量避免這種情況。但是,當我嘗試你的代碼時,它對我來說非常合適。可能是緩存問題,請嘗試清除並重新啓用此模塊。 – Ranjana
你打算重新啓用它嗎?在後端?緩存被禁用並被清除了幾十次 – user3768823