Exemplo n.º 1
0
 /**
  * Execute action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  */
 public function execute()
 {
     $collection = $this->filter->getCollection($this->collectionFactory->create());
     $collectionSize = $collection->getSize();
     $deletedItems = 0;
     foreach ($collection as $synonymGroup) {
         try {
             $this->synGroupRepository->delete($synonymGroup);
             $deletedItems++;
         } catch (\Exception $e) {
             $this->messageManager->addError($e->getMessage());
         }
     }
     if ($deletedItems != 0) {
         if ($collectionSize != $deletedItems) {
             $this->messageManager->addError(__('Failed to delete %1 synonym group(s).', $collectionSize - $deletedItems));
         }
         $this->messageManager->addSuccess(__('A total of %1 synonym group(s) have been deleted.', $deletedItems));
     }
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setPath('*/*/');
 }
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * @param string $name
  * @param string $primaryFieldName
  * @param string $requestFieldName
  * @param CollectionFactory $blockCollectionFactory
  * @param FilterPool $filterPool
  * @param array $meta
  * @param array $data
  */
 public function __construct($name, $primaryFieldName, $requestFieldName, CollectionFactory $blockCollectionFactory, FilterPool $filterPool, array $meta = [], array $data = [])
 {
     parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
     $this->collection = $blockCollectionFactory->create();
     $this->filterPool = $filterPool;
 }