Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MassDelete.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
10 use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
15 
20 {
25 
32  public function __construct(
33  Context $context,
35  CollectionFactory $collectionFactory,
37  ) {
38  parent::__construct($context, $filter, $collectionFactory);
39  $this->customerRepository = $customerRepository;
40  }
41 
46  protected function massAction(AbstractCollection $collection)
47  {
48  $customersDeleted = 0;
49  foreach ($collection->getAllIds() as $customerId) {
50  $this->customerRepository->deleteById($customerId);
51  $customersDeleted++;
52  }
53 
54  if ($customersDeleted) {
55  $this->messageManager->addSuccess(__('A total of %1 record(s) were deleted.', $customersDeleted));
56  }
58  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
59  $resultRedirect->setPath($this->getComponentRefererUrl());
60 
61  return $resultRedirect;
62  }
63 }
__()
Definition: __.php:13
__construct(Context $context, Filter $filter, CollectionFactory $collectionFactory, CustomerRepositoryInterface $customerRepository)
Definition: MassDelete.php:32