Hi, I am trying to implement a new action in the order grid, however I don't know what is the logic that my code must have to work. Below is an image of what I want to do, as well as a fragment of the code I have implemented.
public function execute()
{
$request = $this->getRequest();
$orderIds = $request->getPost('selected', []);
if (empty($orderIds)) {
$this->getMessageManager()->addErrorMessage(__('No orders found.'));
return $this->_redirect('sales/order/index');
}
//print_r(orderIds) // Selected Order Ids
$orderCollection = $this->orderCollectionFactory->create();
$orderCollection->addFieldToFilter('entity_id', ['in' => $orderIds]);
try {
//Add logic here
foreach ($orderCollection as $order) {
}
} catch (\Exception $e) {
$message = "An unknown error occurred while changing selected orders.";
$this->getMessageManager()->addErrorMessage(__($message));
}
return $this->_redirect('sales/order/index');
}