1

For debug purposes, I need to change the status of some orders back to Processing, after they've been already shipped, so the status is Complete.

I'm trying to do this programmatically, so I deleted the shipments of the order, and also the Invoices, but I cannot force the status to get back to Processing and it remains Complete.

Is it possible to do it, or once the status is complete, one cannot go back in the status flow?

Just a snippet of code:

protected function deleteShipments(){
    foreach($this->_ordersToProcess as $incrementId){
        $myOrder = $this->_order->loadByIncrementId($incrementId);

        if($this->_registry->registry('isSecureArea')){
            $this->_registry->unregister('isSecureArea');
        }
        $this->_registry->register('isSecureArea', true);

        $_shipments = $myOrder->getShipmentsCollection();

        if($_shipments){
            foreach($_shipments as $_shipment){
                $_shipment->delete();
            }
        }   

        $_invoices = $myOrder->getInvoiceCollection();

        if($_invoices){
            foreach($_invoices as $invoice){
                $invoice->delete();
            }
        }

        $myOrder->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, true)->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING, true); 
        $myOrder->save();
    }

}
sissy
  • 2,908
  • 2
  • 28
  • 54

1 Answers1

0

Order statuses cannot be changed in the admin panel, as it disrupts the business logic of Magento itself. Generally, it’s only possible to cancel, hold and unhold pending orders. If you want to cancel an order with a ‘Processing’ status or ‘Complete" status you will have to create a credit note for this.

For more info you can look here https://www.mag-manager.com/useful-articles/magento-orders-management/magento-change-order-status-to-any-from-any/

Abhinav Kumar Singh
  • 2,325
  • 1
  • 10
  • 11
  • Well, but this is an extension that makes what I would like to do... so in some way it IS possible to force the change of status from one status to another, even if it would result in some not consistent magento status. I know it is not possible from the admin panel, but I'm not a simple user, so i want to dig into order process programmatically as the extension does ;) – sissy Feb 15 '18 at 08:44