Magento-向销售订单视图页面添加按钮(观察员/事件) [英] Magento - Add Button to Sales Order View Page (Observer/Event)

查看:68
本文介绍了Magento-向销售订单视图页面添加按钮(观察员/事件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在销售订单视图"页面上添加自定义打印按钮(如打印发票)( 销售">订单">订单编号..."视图 ) .

I'm trying to add a custom printing button (like print invoice) on the Sales Order View page (Sales > Orders > Order #... view).

我已经成功完成了一个操作,但是现在有两个位于同一页面的模块.因此,我正在尝试执行观察者/事件方法,并且遇到了麻烦.

I've done this successfully with a but now have two modules that that same page. Therefore I'm trying to do the Observer/Event method and am running into trouble.

这就是我进行大规模动作打印时所需要的,并且效果很好(仅上一页(销售">订单").

This is what I have for the Mass Action printing and it works great (previous page only (Sales > Orders).

$block = $observer->getEvent()->getBlock();

// Mass Action Printing option
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
     && $block->getRequest()->getControllerName() == 'sales_order')
     {
        $block->addItem('test_mass_print', array(
            'label' => 'Print Test',
            'url' => Mage::app()->getStore()->getUrl('orderforms/order/pdfTest'),
        ));
      }

现在,当我尝试为产品视图页面(在同一功能下)添加按钮时:

Now when I try to add the button for the Product View page (under the same function):

// Order View Page button
        if(get_class($block) =='Mage_Adminhtml_Block_Sales_Order_View'
            && $block->getRequest()->getControllerName() == 'sales_order')
        {
            $this->_addButton('test_print', array(
                'label'     => Mage::helper('sales')->__('Test'),
                'onclick'   => Mage::app()->getStore()->getUrl('orderforms/order/print'),
                'class'     => 'go'
            ));
        }

我不断收到这样的错误:

I keep getting errors like this:

Fatal error: Call to undefined method Company_Test_Model_Observer::_addButton() in app/code/local/Company/Test/Model/Observer.php on line 24

我尝试过:

  • $ block-> _ addButton
  • $ block-> _ addItem

,但似乎没有任何效果. 为什么这不起作用?

but nothing seems to work. Why is this not working???

推荐答案

发布后我解决了一点.对我来说,解决方法如下:

I solved it a little bit after I posted. The solution for me was the following:

// Order View Page button
        if(get_class($block) =='Mage_Adminhtml_Block_Sales_Order_View'
            && $block->getRequest()->getControllerName() == 'sales_order')
        {
            $block->addButton('test_print', array(
                'label'     => 'Test',
                'onclick'   => 'setLocation(\'' . $block->getUrl('html/sales_order/print') . '\')',
                'class'     => 'go'
            ));
        }

这篇关于Magento-向销售订单视图页面添加按钮(观察员/事件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆