How to Add a Custom Button to Admin Sales Order View in Magento2
1. Create a plugin in Company/Module/etc/adminhtml/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"><type name="Magento\Backend\Block\Widget\Button\Toolbar"><plugin name="Company_Module::pluginBefore" type="Company\Module\Plugin\PluginBefore" /></type></config>
2. Then in Company/Module/Plugin/PluginBefore.php
<?phpnamespace Company\Module\Plugin;class PluginBefore{protected $view;public function __construct(\Magento\Sales\Block\Adminhtml\Order\View $view){$this->view = $view;}public function beforePushButtons(\Magento\Backend\Block\Widget\Button\Toolbar\Interceptor $subject,\Magento\Framework\View\Element\AbstractBlock $context,\Magento\Backend\Block\Widget\Button\ButtonList $buttonList) {$orderIds = $this->view->getOrderId();$message = 'Are you sure you want to do this?'.$orderIds;$this->_request = $context->getRequest();if($this->_request->getFullActionName() == 'sales_order_view'){$buttonList->add('mybutton',['label' => __('Update Log'),'onclick' => "confirmSetLocation('{$message}','{}')",'class' => 'go'],-1);}}}
3. Clear Magento cache and run update command
php bin/magento setup:upgrade
4. Finally you will see the button in backened
标签
热门文章
- 1 Magento ver. 2.2.0-dev - A technical prob... 16582
- 2 ECS git pull 代码很慢的问题 14715
- 3 玩客云监工客户端 13207
- 4 Magento 2 UI Form Validation 13124
- 5 Codeigniter SSL 强制重定向至https访问 13008
- 6 magento2 完整卸载模块的正确姿势 12642
- 7 Magento fix 500 12283
- 8 Magento index is locked by another reinde... 10741
- 9 Ubuntu删除日志文件 9014
- 10 Magento 2安装ElasticSearch 6.x搜索引擎-Ub... 8624
微信公众号
