MassDelete.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Smartwave\Dailydeals\Controller\Adminhtml\Dailydeal;
  3. class MassDelete extends \Magento\Backend\App\Action
  4. {
  5. /**
  6. * Mass Action Filter
  7. *
  8. * @var \Magento\Ui\Component\MassAction\Filter
  9. */
  10. protected $filter;
  11. /**
  12. * Collection Factory
  13. *
  14. * @var \Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\CollectionFactory
  15. */
  16. protected $collectionFactory;
  17. /**
  18. * constructor
  19. *
  20. * @param \Magento\Ui\Component\MassAction\Filter $filter
  21. * @param \Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\CollectionFactory $collectionFactory
  22. * @param \Magento\Backend\App\Action\Context $context
  23. */
  24. public function __construct(
  25. \Magento\Ui\Component\MassAction\Filter $filter,
  26. \Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\CollectionFactory $collectionFactory,
  27. \Magento\Backend\App\Action\Context $context
  28. ) {
  29. $this->filter = $filter;
  30. $this->collectionFactory = $collectionFactory;
  31. parent::__construct($context);
  32. }
  33. /**
  34. * execute action
  35. *
  36. * @return \Magento\Backend\Model\View\Result\Redirect
  37. */
  38. public function execute()
  39. {
  40. $collection = $this->filter->getCollection($this->collectionFactory->create());
  41. $delete = 0;
  42. foreach ($collection as $item) {
  43. /** @var \Smartwave\Dailydeals\Model\Dailydeal $item */
  44. $item->delete();
  45. $delete++;
  46. }
  47. $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete));
  48. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  49. $resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
  50. return $resultRedirect->setPath('*/*/');
  51. }
  52. }