magento2 – How to override a controller using Plugin?


I want to override abstact class controller MagentoSalesControllerAbstractControllerReorder.php using Plugin.

How can I do that?

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="MagentoSalesControllerAbstractControllerReorder">
        <plugin name="testing_reorder"
                type="testingReorderButtonPluginMagentoSalesControllerAbstractControllerReorderPlugin"/>
    </type>
</config>

but I am so new to Magento and looking at documents, I am still confused.

This is the reorder.php, I just want to remove a couple lines from this php file which I have marked/commented on below code.

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace MagentoSalesControllerAbstractController;

use MagentoFrameworkAppAction;
use MagentoFrameworkRegistry;
use MagentoFrameworkAppActionHttpPostActionInterface;

/**
 * Abstract class for controllers Reorder(Customer) and Reorder(Guest)
 *
 * @package MagentoSalesControllerAbstractController
 */
abstract class Reorder extends ActionAction implements HttpPostActionInterface
{
    /**
     * @var MagentoSalesControllerAbstractControllerOrderLoaderInterface
     */
    protected $orderLoader;

    /**
     * @var Registry
     */
    protected $_coreRegistry;


    /**
     * @param ActionContext $context
     * @param OrderLoaderInterface $orderLoader
     * @param Registry $registry
     */
    public function __construct(
        ActionContext $context,
        OrderLoaderInterface $orderLoader,
        Registry $registry
    ) {
        $this->orderLoader = $orderLoader;
        $this->_coreRegistry = $registry;
        parent::__construct($context);
    }

    /**
     * Action for reorder
     *
     * @return MagentoFrameworkControllerResultInterface
     */
    public function execute()
    {
        $result = $this->orderLoader->load($this->_request);
        if ($result instanceof MagentoFrameworkControllerResultInterface) {
            return $result;
        }
        $order = $this->_coreRegistry->registry('current_order');
        /** @var MagentoFrameworkControllerResultRedirect $resultRedirect */
        $resultRedirect = $this->resultRedirectFactory->create();

        /* @var $cart MagentoCheckoutModelCart */
        $cart = $this->_objectManager->get(MagentoCheckoutModelCart::class);
        $items = $order->getItemsCollection();

        foreach ($items as $item) {
            try {
                $cart->addOrderItem($item);
            } catch (MagentoFrameworkExceptionLocalizedException $e) {
                //TO REMOVEEEEE
                if ($this->_objectManager->get(MagentoCheckoutModelSession::class)->getUseNotice(true)) {
                    $this->messageManager->addNoticeMessage($e->getMessage());
                } else {
                    $this->messageManager->addErrorMessage($e->getMessage());
                }
                return $resultRedirect->setPath('*/*/history');
                //END REMOVEEEE
            } catch (Exception $e) {
                $this->messageManager->addExceptionMessage(
                    $e,
                    __('We can't add this item to your shopping cart right now.')
                );
                return $resultRedirect->setPath('checkout/cart');
            }
        }

        $cart->save();
        return $resultRedirect->setPath('checkout/cart');
    }
}