我已经准备好在大规模行动期间调用的函数。
/**
* Hold selected orders
*
* @param AbstractCollection $collection
* @return \Magento\Backend\Model\View\Result\Redirect
*/
protected function massAction(AbstractCollection $collection)
{
$countDeleteOrder = 0;
$model = $this->_objectManager->create('Magento\Sales\Model\Order');
foreach ($collection->getItems() as $order) {
if (!$order->getEntityId()) {
continue;
}
$loadedOrder = $model->load($order->getEntityId());
$loadedOrder->setState(\Magento\Sales\Model\Order::STATE_PROCESSING, true);
$loadedOrder->setStatus(\Magento\Sales\Model\Order::STATE_PROCESSING);
$loadedOrder->addStatusToHistory($order->getStatus(), 'Order processed successfully with reference');
$loadedOrder->save();
}
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->getComponentRefererUrl());
return $resultRedirect;
}
但是,它仅设置状态,因为状态不起作用。我正在尝试将状态从新更改为正在处理,但是上面的代码不起作用。有人可以帮我吗?