【问题标题】:How to add a button to Customer Information Tab in Magento?如何在 Magento 的客户信息选项卡中添加按钮?
【发布时间】: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


    【解决方案1】:

    所以我认为问题出在我的 if 语句上,因为其他一切都在工作。所以首先这是我的观察者代码。

    Observer.php

    <?php
    class Rdtmodules_GroupNotification_Model_Observer
    {
        public function sendNotification(Varien_Event_Observer $observer){
            $block = $observer->getEvent()->getData('block');
            if($block->getNameInLayout() == 'customer_edit' && $block->getRequest()->getControllerName() == 'customer') {
                $block->addButton('test_print', array(
                    'label'     => 'Test',
                    'onclick'   =>'setLocation(\'' . $block->getUrl('html/sales_order/print') . '\')',
                    'class'     => 'go'
                ));
            }
        }       
    }
    

    $block-&gt;getId() 没有返回任何东西,这就是它不起作用的原因。此外,控制器名称不是 customer_edit 它只是 customer o.o。

    我发现这是我在布局中打印了控制器名称、动作名称和块名称。

    echo "Controller Name: " . $block->getRequest()->getControllerName();
    echo "Action Name: " . $block->getRequest()->getActionName();
    echo "Block Name: " . $block->getNameInLayout();
    

    这就是我发现问题所在的方式。

    非常有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多