If you want to add a new button on the sales order view page in the admin side then you have to do that by the plugin.
Please follow the below steps.
Step 1: Create a di.xml file on the below path and paste the below code in it.
Path: app/code/Magemonkeys/CustomOrderButton/etc/adminhtml/di.xml
1 2 3 4 5 6 7 |
<?xml version="1.0"?> <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="add_custom_button_toolbar" type="Magemonkeys\CustomOrderButton\Plugin\CustomButtonPlugin" /> </type> </config> |
Step 2: Create the plugin file on the below path and paste the below code in it.
Path: app/code/Magemonkeys/CustomOrderButton/Plugin/CustomButtonPlugin.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 |
<?php declare(strict_types=1); namespace Magemonkeys\CustomOrderButton\Plugin; 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 CustomButtonPlugin { public function beforePushButtons(ToolbarContext $toolbar,AbstractBlock $context,ButtonList $buttonList): array { $orderObject = false; $layoutName = $context->getNameInLayout(); if ('sales_order_edit' == $layoutName) { $orderObject = $context->getOrder(); } if ($orderObject) { $url = 'My Custom URL' $buttonList->add('custom_btn',['label' => __('Custom Button'),'on_click' => sprintf("location.href = '%s';", $url),'class' => 'primary custom_button','id' => 'custom_btn']); } return [$context, $buttonList]; } } ?> |
Please follow the below methods to get the attribute options...
Update product attribute value programmatically in Magento 2 . [crayon-62878002c18d0436075282/]...
If you want restrict customer to checkout based on your...
Sometime we need to set html data without load or...
If you want get query string params in controller file,...