1

di.xml


<?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\Context">
        <plugin name="add_custom_button_sales_veiw" type="MyModule\RK\Plugin\Widget\Context" sortOrder="1"/>
    </type>
</config>

Context.php

<?php
namespace MyModule\RK\Plugin\Widget;

class Context
{
    public function afterGetButtonList(
        \Magento\Backend\Block\Widget\Context $subject,
         $buttonList
    )
    {
        if($subject->getRequest()->getFullActionName() == 'sales_order_view'){
            $buttonList->add(
                'custom_button',
                [
                    'label' => 'test',
                    'onclick' => "setLocation('window.location.href')",
                    'class' => 'ship'
                ]
            );
        }

        return $buttonList;
    }
}

Review button is not displaying on order view page what i am doing wrong ??

2
  • Whats your di.xml location?
    – Sohel Rana
    Commented Oct 3, 2016 at 9:00
  • vendor/modulename/etc/adminhtml/di.xml Commented Oct 3, 2016 at 9:05

1 Answer 1

4

Change your di.xml [Vendor/Module/etc/adminhtml/di.xml]:

<?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\Context">
        <plugin name="add_custom_button_sales_veiw" type="Vendor\Module\Plugin\Widget\Context" sortOrder="1"/>
    </type>
</config>

Create plugin [Vendor/Module/Plugin/Widget/Context.php]

namespace Vedor\Module\Plugin\Widget;


class Context
{
    public function afterGetButtonList(
        \Magento\Backend\Block\Widget\Context $subject,
        $buttonList
    )
    {
        if($subject->getRequest()->getFullActionName() == 'sales_order_view'){
            $buttonList->add(
                'custom_button',
                [
                    'label' => __('Custom Button'),
                    'onclick' => "setLocation('window.location.href')",
                    'class' => 'ship'
                ]
            );
        }

        return $buttonList;
    }
}

Clear cache.

Read here for more detail

10
  • its not working yet ? I think function is not calling because i try to print hello in this function but nothing is printing. May be problem in my di.xml. Please suggest me Commented Oct 3, 2016 at 6:49
  • Check updated answer.
    – Sohel Rana
    Commented Oct 3, 2016 at 7:09
  • yes i am doing exactly same but not working ... Commented Oct 3, 2016 at 7:26
  • Which version you have tried? Make sure your module active.
    – Sohel Rana
    Commented Oct 3, 2016 at 7:27
  • 2.1.0 and my module is active Commented Oct 3, 2016 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.