cancel
Showing results for 
Search instead for 
Did you mean: 

Add custom buttons to admin order view page and write funtionality to it

SOLVED

Add custom buttons to admin order view page and write funtionality to it

I am new to magento. I want to add Dispatch button to Order view page (Admin) and would like to write funtionality it. Please help me out in this ASAP.

4 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Add custom buttons to admin order view page and write funtionality to it

Re: Add custom buttons to admin order view page and write funtionality to it

Hi @tippanna_pawar 

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="Vendor_Model::pluginBefore" type="Vendor\Model\Plugin\PluginBefore" />
    </type>
</config>

Then add code with Plugin/PluginBefore.php

namespace Vendor\Modelname\Plugin;

class PluginBefore
{
    public function beforePushButtons(
        \Magento\Backend\Block\Widget\Button\Toolbar\Interceptor $subject,
        \Magento\Framework\View\Element\AbstractBlock $context,
        \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
    ) {

        $this->_request = $context->getRequest();
        if($this->_request->getFullActionName() == 'sales_order_view'){
              $buttonList->add(
                'mybutton',
                ['label' => __('Dispatch'), 'onclick' => 'setLocation(window.location.href)', 'class' => 'reset'],
                -1
            );
        }

    }
}

 

Problem solved? Click Accept as Solution!

View solution in original post

Re: Add custom buttons to admin order view page and write funtionality to it

Hi @tippanna_pawar 

Glad to hear that, it works for you!

For order status change, follow the below link.

https://magento.stackexchange.com/a/164613


I hope it will help you!

View solution in original post

Re: Add custom buttons to admin order view page and write funtionality to it

Hi @tippanna_pawar 

You can follow below link to create an admin controller.

magento-2-how-to-create-an-admin-controller-and-a-new-acl/ 

Then you can call this controller from the button you have created.

I hope it will help you!

View solution in original post

11 REPLIES 11

Re: Add custom buttons to admin order view page and write funtionality to it

Re: Add custom buttons to admin order view page and write funtionality to it

Hi Vimal,

 

Thanks for your valuable reply. I have created button but now i am redirecting to custom index Controller. In controller i want to change order status to Dispatched and want to send Email regarding.  Please help me on this also

Re: Add custom buttons to admin order view page and write funtionality to it

Hi @tippanna_pawar 

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="Vendor_Model::pluginBefore" type="Vendor\Model\Plugin\PluginBefore" />
    </type>
</config>

Then add code with Plugin/PluginBefore.php

namespace Vendor\Modelname\Plugin;

class PluginBefore
{
    public function beforePushButtons(
        \Magento\Backend\Block\Widget\Button\Toolbar\Interceptor $subject,
        \Magento\Framework\View\Element\AbstractBlock $context,
        \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
    ) {

        $this->_request = $context->getRequest();
        if($this->_request->getFullActionName() == 'sales_order_view'){
              $buttonList->add(
                'mybutton',
                ['label' => __('Dispatch'), 'onclick' => 'setLocation(window.location.href)', 'class' => 'reset'],
                -1
            );
        }

    }
}

 

Problem solved? Click Accept as Solution!

Re: Add custom buttons to admin order view page and write funtionality to it

Hi @tippanna_pawar 

Glad to hear that, it works for you!

For order status change, follow the below link.

https://magento.stackexchange.com/a/164613


I hope it will help you!

Re: Add custom buttons to admin order view page and write funtionality to it

Thank you for valuable post. Please let me how to create controller on this write functionality for Dispatch event. Please help

 

Re: Add custom buttons to admin order view page and write funtionality to it

Thank you so much.

Re: Add custom buttons to admin order view page and write funtionality to it

Hi @tippanna_pawar 

Can you tell me that all resolved or need any help?

Re: Add custom buttons to admin order view page and write funtionality to it

Hi vimal,

 

Still i am in problem. Can you guide me how to create controller on above click event. what could be the controller link for button

Re: Add custom buttons to admin order view page and write funtionality to it

Hi @tippanna_pawar 

You can follow below link to create an admin controller.

magento-2-how-to-create-an-admin-controller-and-a-new-acl/ 

Then you can call this controller from the button you have created.

I hope it will help you!