stopWordRepository = $stopWordRepository; $this->collectionFactory = $collectionFactory; $this->filter = $filter; $this->indexerRegistry = $indexerRegistry; } /** * {@inheritdoc} */ public function execute() { $idsToRemove = []; $ids = $this->getRequest()->getParam(StopWordInterface::STOP_WORD_ID); if ($ids) { $idsToRemove = [$ids]; } if ($this->getRequest()->getParam(Filter::SELECTED_PARAM) || $this->getRequest()->getParam(Filter::EXCLUDED_PARAM) ) { $idsToRemove = $this->filter->getCollection($this->collectionFactory->create())->getAllIds(); } if ($idsToRemove) { foreach ($idsToRemove as $id) { try { $this->stopWordRepository->deleteById($id); } catch (\Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); } } $this->messageManager->addSuccessMessage( __('%1 stop word(s) was successfully removed', count($idsToRemove)) ); $this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID)->invalidate(); } else { $this->messageManager->addErrorMessage(__('Please select Stop Word(s)')); } return $this->resultRedirectFactory->create()->setPath('*/*/'); } }