出于调试目的,我需要在某些订单已经发货后将其状态更改回处理中,因此状态为完成。
我正在尝试以编程方式执行此操作,因此我删除了订单的发货以及发票,但我无法强制状态返回到处理中并且它仍然是完整的。
是否可以这样做,或者一旦状态完成,就无法返回状态流?
只是一段代码:
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();
}
}