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 ??

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Oct 3, 2016 at 6:18
2
  • Whats your di.xml location? 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

answered Oct 3, 2016 at 6:39
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. 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. Commented Oct 3, 2016 at 7:27
  • 2.1.0 and my module is active Commented Oct 3, 2016 at 7:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.