如何在后端按钮上添加操作

时间:2021-02-26 12:56:20

标签: magento2

我试图简单地从管理销售/发货/视图中的打印按钮复制操作。

使用原始“打印”按钮和我自定义的“打印采购订单”按钮查看下图。

Admin Backend - Sales - Shipments - Details

我扩展了 Magento\Shipping\Block\Adminhtml\View 并以这种方式添加了新按钮:

use Magento\Shipping\Block\Adminhtml\View as OriginalView;

class View extends OriginalView
{

    protected function _construct()
    {
        parent::_construct();

        if ($this->getShipment()->getId()) {
            $this->buttonList->add(
                'purchase_order',
                [
                    'label' => __('Print Purchase Order'),
                    'class' => 'save',
                    'onclick' => 'setLocation(\'' . $this->getPurchaseOrderUrl() . '\')',
                ]
            );
        }
    }

    /**
     * @return string
     */
    public function getPurchaseOrderUrl()
    {
        return $this->getUrl('sales/shipment/printorder', ['shipment_id' => $this->getShipment()->getId()]);
    }

}

上面的代码运行良好,但是没有调用我的 Action。 我添加了 PrintOrderAction 如下图所示:

See the PrintOrderAction path and code

(类似于“打印”按钮的原始 PrintAction。 但是,当我单击我的新按钮时,出现以下错误,并且我被重定向到管理仪表板:

Admin Dashboard - Error message

<块引用>

无效的安全或表单密钥。请刷新页面。

知道我错过了什么吗?

0 个答案:

没有答案