Let’s initiate a discussion!!
To add a custom button on the admin order view page, you need to create a before plugin for the PushButtons() method from the Magento\Backend\Block\Widget\Button\Toolbar class.
Create di.xml file under the adminhtml scope,
Path: app/code/Magemonkeys/OrderViewButton/etc/adminhtml/di.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <!-- Add new Button on sales order view toolbar --> <type name="Magento\Backend\Block\Widget\Button\Toolbar"> <plugin name="add_sales_button_toolbar" type="Magemonkeys\OrderViewButton\Plugin\Block\Widget\Button\ToolbarPlugin" /> </type> </config> |
create ToolbarPlugin.php
Path: app/code/Magemonkeys/OrderViewButton/Plugin/Block/Widget/Button/ToolbarPlugin.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?php declare(strict_types=1); namespace Magemonkeys\OrderViewButton\Plugin\Block\Widget\Button; use Magento\Sales\Block\Adminhtml\Order\Create; use Magento\Framework\View\Element\AbstractBlock; use Magento\Backend\Block\Widget\Button\ButtonList; use Magento\Backend\Block\Widget\Button\Toolbar as ToolbarContext; class ToolbarPlugin { /** * @param ToolbarContext $toolbar * @param AbstractBlock $context * @param ButtonList $buttonList * @return array */ public function beforePushButtons( ToolbarContext $toolbar, AbstractBlock $context, ButtonList $buttonList ): array { $order = false; $nameInLayout = $context->getNameInLayout(); if ('sales_order_edit' == $nameInLayout) { $order = $context->getOrder(); } if ($order) { $url = "YOUR_URL"; // add your full url $buttonList->add( 'my_button', [ 'label' => __('My Button'), 'on_click' => sprintf("location.href = '%s';", $url), 'class' => 'primary', 'id' => 'my_button' ] ); } return [$context, $buttonList]; } }<code> |
Output :
[crayon-64216e2c68159796849537/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.