I have added custom button in sales order view on admin .But I need the custom button next to cancel button.
1 Answer
Step.1 Add di.xml in your module
/public_html/staging2/app/code/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\Button\Toolbar">
<plugin name="AddButtonInOrder" type="MagePsycho\Customshipping\Plugin\Adminhtml\AddButtonInOrder" />
</type>
</config>
Step.2 Add AddButtonInOrder.php
/public_html/staging2/app/code/MagePsycho/Customshipping/Plugin/Adminhtml/AddButtonInOrder.php
<?php
/**
* Copyright © 2018 Codealist. All rights reserved.
*
* @category Class
* @package Codealist_OrderViewButton
* @author Codealist <[email protected]>
* @license See LICENSE.txt for license details.
* @link https://www.codealist.com/
*/
namespace Vendor\Module\Plugin\Adminhtml;
class AddButtonInOrder
{
/**
* @param \Magento\Backend\Block\Widget\Button\Toolbar\Interceptor $subject
* @param \Magento\Framework\View\Element\AbstractBlock $context
* @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
*/
public function beforePushButtons(
\Magento\Backend\Block\Widget\Button\Toolbar\Interceptor $subject,
\Magento\Framework\View\Element\AbstractBlock $context,
\Magento\Backend\Block\Widget\Button\ButtonList $buttonList
)
{
if ($context->getRequest()->getFullActionName() == 'sales_order_view') {
$order_id = $context->getRequest()->getParam('order_id');
$url = $context->getUrl('sales/*/email', ['pickup_ready'=> 'pickup_ready']);
$buttonList->add(
'pickupReady',
['label' => __('Pickup Ready'), 'onclick' => 'deleteConfirm(\'' . __(
'Are you sure you want to send a "Ready for Collection" email to customer?'
) . '\', \'' . $url . '\')', 'class' => 'reset'],
-1
);
}
}
}
upvote and accept solution if helps you :)
-
Please donot ask to update or accept your answer...... Ask to accept the answer like forcing user accept answer– Amit Bera ♦Commented May 27, 2021 at 6:46
-
Some user dont know thats why I am just added here that line..and I am not forcing..I added if help you then accept answer. Commented May 27, 2021 at 10:51