filter->getCollection($this->collectionFactory->create()); $ids = array_map('intval', $collection->getAllIds()); $updated = 0; if ($ids) { $updated = $this->resource->getConnection()->update( $this->resource->getTableName('esun_legacy_order'), ['customer_id' => null, 'link_status' => 'unlinked'], ['legacy_order_id IN (?)' => $ids, 'customer_id IS NOT NULL'] ); } $this->messageManager->addSuccessMessage( __('%1 legacy order(s) were unbound from customers.', $updated) ); $alreadyUnlinked = count($ids) - $updated; if ($alreadyUnlinked > 0) { $this->messageManager->addNoticeMessage( __('%1 selected order(s) were already unbound.', $alreadyUnlinked) ); } } catch (\Throwable $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); } return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index'); } }