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
-
Whats your di.xml location?Sohel Rana– Sohel Rana2016年10月03日 09:00:49 +00:00Commented Oct 3, 2016 at 9:00
-
vendor/modulename/etc/adminhtml/di.xmlRamkishan Suthar– Ramkishan Suthar2016年10月03日 09:05:34 +00:00Commented Oct 3, 2016 at 9:05
1 Answer 1
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
-
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 meRamkishan Suthar– Ramkishan Suthar2016年10月03日 06:49:13 +00:00Commented Oct 3, 2016 at 6:49
-
Check updated answer.Sohel Rana– Sohel Rana2016年10月03日 07:09:41 +00:00Commented Oct 3, 2016 at 7:09
-
yes i am doing exactly same but not working ...Ramkishan Suthar– Ramkishan Suthar2016年10月03日 07:26:59 +00:00Commented Oct 3, 2016 at 7:26
-
Which version you have tried? Make sure your module active.Sohel Rana– Sohel Rana2016年10月03日 07:27:54 +00:00Commented Oct 3, 2016 at 7:27
-
2.1.0 and my module is activeRamkishan Suthar– Ramkishan Suthar2016年10月03日 07:33:47 +00:00Commented Oct 3, 2016 at 7:33
default