Magento 2:无法将订单状态更改回“完成处理”

时间:2018-02-07 11:56:16

标签: magento magento2 orders magento2.1

出于调试目的,我需要将某些订单的状态更改回处理后已经发货,因此状态为完成。

我正在尝试以编程方式执行此操作,因此我删除了订单的发货以及发票,但我无法强制状态返回到处理并且它仍然是完整的。

是否可以这样做,或者一旦状态完成,就无法回到状态流程中?

只是一段代码:

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();
    }

}

1 个答案:

答案 0 :(得分:0)

订单状态无法在管理面板中更改,因为它会破坏Magento本身的业务逻辑。通常,只能取消,保留和取消挂单。如果您要取消处理“处理”状态或“完成”#34;您需要为此创建一个信用票据。

有关详细信息,请查看此处https://www.mag-manager.com/useful-articles/magento-orders-management/magento-change-order-status-to-any-from-any/