【发布时间】:2014-12-30 17:58:26
【问题描述】:
我正在尝试在Customers->Account Information 选项卡中添加一个按钮。我希望按钮在单击时执行操作。我想在自定义模块中执行此操作。我不太喜欢重写核心文件或任何类的想法。根据我在谷歌上搜索的内容,人们说您可以使用 Observer 来做到这一点,例如 here ,如果这是真的,那么我想这样做。
我知道如何制作一个基本模块,我需要帮助的是如何在不重写文件/类的情况下将按钮放在特定选项卡中?
2013 年 11 月 3 日上午 11 点更新:
这里是截图
我想在此选项卡上添加按钮。
2014 年 11 月 3 日下午 2:48 更新
到目前为止,这是我的代码,也许我在某个地方犯了错误。
我的文件结构
-app
-local
-Rdtmodules
-ChangeGroupNotification
-etc
-config.xml
-Model
-Observer.php
-etc
-modules
-Rdtmodules_ChangeGroupNotification.xml
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Rdtmodules_ChangeGroupNotification>
<version>1.0.0</version>
</Rdtmodules_ChangeGroupNotification>
</modules>
<global>
<models>
<rdtmodules_changegroupnotification>
<class>Rdtmodules_ChangeGroupNotification_Model</class>
</rdtmodules_changegroupnotification>
</models>
<events>
<adminhtml_block_html_before>
<observers>
<rdtmodules_changegroupnotification>
<class>rdtmodules_changegroupnotification/observer</class>
<method>sendCustomerGroupChangeNotification</method>
<type>singleton</type>
</rdtmodules_changegroupnotification>
</observers>
</adminhtml_block_html_before>
</events>
</global>
</config>
Observer.php
<?php
class Rdtmodules_ChangeGroupNotification_Model_Observer {
public function sendCustomerGroupChangeNotification(Varien_Event_Observer $observer) {
$block = $observer->getEvent()->getData('block');
if($block->getId() == 'customer_edit' && $block->getRequest()->getControllerName() == 'customer_edit') {
$block->addButton('test_print', array(
'label' => 'Test',
'onclick' =>'setLocation(\'' . $block->getUrl('html/sales_order/print') . '\')',
'class' => 'go'
));
}
}
}
【问题讨论】:
标签: magento events magento-1.8 observers adminhtml