Delete.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Tax\Controller\Adminhtml\Rule;
  8. use Magento\Framework\App\Action\HttpPostActionInterface;
  9. use Magento\Framework\Controller\ResultFactory;
  10. class Delete extends \Magento\Tax\Controller\Adminhtml\Rule implements HttpPostActionInterface
  11. {
  12. /**
  13. * @return \Magento\Backend\Model\View\Result\Redirect
  14. */
  15. public function execute()
  16. {
  17. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  18. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  19. $ruleId = (int)$this->getRequest()->getParam('rule');
  20. try {
  21. $this->ruleService->deleteById($ruleId);
  22. $this->messageManager->addSuccess(__('The tax rule has been deleted.'));
  23. return $resultRedirect->setPath('tax/*/');
  24. } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
  25. $this->messageManager->addError(__('This rule no longer exists.'));
  26. return $resultRedirect->setPath('tax/*/');
  27. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  28. $this->messageManager->addError($e->getMessage());
  29. } catch (\Exception $e) {
  30. $this->messageManager->addError(__('Something went wrong deleting this tax rule.'));
  31. }
  32. return $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*')));
  33. }
  34. }