Delete.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Controller\Adminhtml\Group;
  8. use Magento\Framework\App\Action\HttpPostActionInterface;
  9. use Magento\Framework\Exception\NoSuchEntityException;
  10. class Delete extends \Magento\Customer\Controller\Adminhtml\Group implements HttpPostActionInterface
  11. {
  12. /**
  13. * Delete customer group.
  14. *
  15. * @return \Magento\Backend\Model\View\Result\Redirect
  16. */
  17. public function execute()
  18. {
  19. $id = $this->getRequest()->getParam('id');
  20. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  21. $resultRedirect = $this->resultRedirectFactory->create();
  22. if ($id) {
  23. try {
  24. $this->groupRepository->deleteById($id);
  25. $this->messageManager->addSuccess(__('You deleted the customer group.'));
  26. } catch (NoSuchEntityException $e) {
  27. $this->messageManager->addError(__('The customer group no longer exists.'));
  28. return $resultRedirect->setPath('customer/*/');
  29. } catch (\Exception $e) {
  30. $this->messageManager->addError($e->getMessage());
  31. return $resultRedirect->setPath('customer/group/edit', ['id' => $id]);
  32. }
  33. }
  34. return $resultRedirect->setPath('customer/group');
  35. }
  36. }