Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Delete.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
10 
12 {
18  public function execute()
19  {
20  $resultRedirect = $this->resultRedirectFactory->create();
21  $formKeyIsValid = $this->_formKeyValidator->validate($this->getRequest());
22  $isPost = $this->getRequest()->isPost();
23  if (!$formKeyIsValid || !$isPost) {
24  $this->messageManager->addError(__('Customer could not be deleted.'));
25  return $resultRedirect->setPath('customer/index');
26  }
27 
29  if (!empty($customerId)) {
30  try {
31  $this->_customerRepository->deleteById($customerId);
32  $this->messageManager->addSuccess(__('You deleted the customer.'));
33  } catch (\Exception $exception) {
34  $this->messageManager->addError($exception->getMessage());
35  }
36  }
37 
39  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
40  return $resultRedirect->setPath('customer/index');
41  }
42 }
__()
Definition: __.php:13