Read More
Read More
Menu Close

    Magento 2: How To Restore Canceled Orders

    Hello Friends!!!

    In this article, we will learn how we can restore canceled orders in Magento 2.

    Sometimes we face problems restoring canceled orders and recovering purchase requests from the order view page. So In this article, we will see how to solve this kind of problem.

    Restore Cancel Order Using Controller

    <?php
    
    namespace Vendor\ModuleName\Controller\ControllerName;
    
    use Magento\Framework\App\Action\Action;
    
    class RestoreCancelOrder extends Action
    {
        
        public function __construct(
            Context $context,
            \Magento\Sales\Model\OrderFactory $orderFactory,
            \Magento\Sales\Model\Order $orderModel
        ) {      
            $this->orderFactory = $orderFactory;
            $this->orderModel = $orderModel;
            parent::__construct($context);
        }
    
    
        public function execute()
        {
            $orderId =121;
            $orderData = $this->orderFactory->create()->load($orderId);   
           if($orderData->isCanceled()) {  
            $order = $this->orderModel->load($orderId);
            $order->setState("processing")
                ->setStatus("processing")
                ->save();
                    $orderItems = $order->getAllItems();
                    foreach ($orderItems as $item) {
                        $item->setData("qty_canceled",0)->save();
                }
           }
          
            }
    
      }

    Searching for an experienced
    Magento 2 Company ?
    Read More
    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top