I have added a new button to order view action buttons:
class ReturnButton
{
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(
'returnButton',
['label' => __('New return request'), 'onclick' => 'setLocation(\'http://foo.bar\')', 'class' => 'reset'],
1
);
}
}
}
However, I would need to open a new window, setLocation naturally sets new location for current window. What is the correct way to do this in Magento 2?
Best Answer
Substitute
'setLocation(\'http://foo.bar\')'
with'window.open(\'http://foo.bar\')'
That should do it.