cancel
Showing results for 
Search instead for 
Did you mean: 

Adding extra functionality to processing button in order view page admin

SOLVED

Adding extra functionality to processing button in order view page admin

Hi ,

Currently, processing button of order view page in admin ,on click simply changing status to processing but i would to add some additional functionality to it as mentioned below.

1.convert total due amount to zero

2.Sending email to customer.

 

Please guide me how proceed with this ASAP.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Adding extra functionality to processing button in order view page admin

Hi @tippanna_pawar 

Please override below file within custom module:

vendor/magento/module-sales/Block/Adminhtml/Order/View.php

Add below condition with in _construct():

if ($this->_isAllowedAction('Magento_Sales::testing') && !$order->isCanceled()) {
            $message = __('Are you sure ?');
            $this->addButton(
                'send_notification',
                [
                    'label' => __('Testing Button'),
                    'class' => 'send-email',
                    'onclick' => "confirmSetLocation('{$message}', '{$this->getEmailUrl()}')"
                ]
            );
        }

Create admin controller :

<vedorname>/<modulename>/Controller/Adminhtml/Order/Test.php

Add following code with controller:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace <vedorname>/<modulename>\Controller\Adminhtml\Order;

class Testing extends \Magento\Sales\Controller\Adminhtml\Order
{
    /**
     * Authorization level of a basic admin session
     *
     * @see _isAllowed()
     */
    const ADMIN_RESOURCE = 'Magento_Sales::testing';

    /**
     * Notify user
     *
     * @return \Magento\Backend\Model\View\Result\Redirect
     */
    public function execute()
    {
        $order = $this->_initOrder();
        if ($order) {
            try {
                 /* Add your functionality */
            } catch (\Magento\Framework\Exception\LocalizedException $e) {
                $this->messageManager->addErrorMessage($e->getMessage());
            } catch (\Exception $e) {
                $this->messageManager->addErrorMessage(__('We can\'t send the email order right now.'));
                $this->logger->critical($e);
            }
            return $this->resultRedirectFactory->create()->setPath(
                'sales/order/view',
                [
                    'order_id' => $order->getEntityId()
                ]
            );
        }
        return $this->resultRedirectFactory->create()->setPath('sales/*/');
    }
}

Using this code you can add button on top bar of order view page in admin and create your own functionality.

If issue resolve, Please click on 'Kudos' & Accept as Solution!

View solution in original post

1 REPLY 1

Re: Adding extra functionality to processing button in order view page admin

Hi @tippanna_pawar 

Please override below file within custom module:

vendor/magento/module-sales/Block/Adminhtml/Order/View.php

Add below condition with in _construct():

if ($this->_isAllowedAction('Magento_Sales::testing') && !$order->isCanceled()) {
            $message = __('Are you sure ?');
            $this->addButton(
                'send_notification',
                [
                    'label' => __('Testing Button'),
                    'class' => 'send-email',
                    'onclick' => "confirmSetLocation('{$message}', '{$this->getEmailUrl()}')"
                ]
            );
        }

Create admin controller :

<vedorname>/<modulename>/Controller/Adminhtml/Order/Test.php

Add following code with controller:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace <vedorname>/<modulename>\Controller\Adminhtml\Order;

class Testing extends \Magento\Sales\Controller\Adminhtml\Order
{
    /**
     * Authorization level of a basic admin session
     *
     * @see _isAllowed()
     */
    const ADMIN_RESOURCE = 'Magento_Sales::testing';

    /**
     * Notify user
     *
     * @return \Magento\Backend\Model\View\Result\Redirect
     */
    public function execute()
    {
        $order = $this->_initOrder();
        if ($order) {
            try {
                 /* Add your functionality */
            } catch (\Magento\Framework\Exception\LocalizedException $e) {
                $this->messageManager->addErrorMessage($e->getMessage());
            } catch (\Exception $e) {
                $this->messageManager->addErrorMessage(__('We can\'t send the email order right now.'));
                $this->logger->critical($e);
            }
            return $this->resultRedirectFactory->create()->setPath(
                'sales/order/view',
                [
                    'order_id' => $order->getEntityId()
                ]
            );
        }
        return $this->resultRedirectFactory->create()->setPath('sales/*/');
    }
}

Using this code you can add button on top bar of order view page in admin and create your own functionality.

If issue resolve, Please click on 'Kudos' & Accept as Solution!

View solution in original post