Today I am trying to overwrite the \Magento\Sales\Block\Adminhtml\Order\View
file, but it's not working. The same coding working on core files.
My Code is
<?php
namespace SR\StackExchange\Block\Adminhtml\Order;
class View extends \Magento\Sales\Block\Adminhtml\Order\View
{
/**
* Get URL for back (reset) button
*
* @return string
*/
public function getCustomOrderUrl()
{
$params = [
'id' => $this->getOrderId(),
'store' => 0
];
return $this->getUrl('stackexchange/stackexchange/order');
}
/**
* Constructor
*
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function _construct()
{
$this->buttonList->add(
'custom_button',
[
'label' => __('Custom Button'),
'class' => 'action-secondary',
'on_click' => sprintf("location.href = '%s';", $this->getCustomOrderUrl()),
]
);
parent::_construct();
}
}
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\Sales\Block\Adminhtml\Order\View">
<plugin name="custom_button" type="SR\StackExchange\Block\Adminhtml\Order\View" sortOrder="1"/>
</type>
</config>