Delete.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Rate;
  8. use Magento\Framework\Exception\NoSuchEntityException;
  9. use Magento\Framework\Controller\ResultFactory;
  10. class Delete extends \Magento\Tax\Controller\Adminhtml\Rate
  11. {
  12. /**
  13. * Delete Rate and Data
  14. *
  15. * @return \Magento\Backend\Model\View\Result\Redirect|void
  16. */
  17. public function execute()
  18. {
  19. if ($rateId = $this->getRequest()->getParam('rate')) {
  20. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  21. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  22. try {
  23. $this->_taxRateRepository->deleteById($rateId);
  24. $this->messageManager->addSuccess(__('You deleted the tax rate.'));
  25. return $resultRedirect->setPath("*/*/");
  26. } catch (NoSuchEntityException $e) {
  27. $this->messageManager->addError(
  28. __('We can\'t delete this rate because of an incorrect rate ID.')
  29. );
  30. return $resultRedirect->setPath("tax/*/");
  31. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  32. $this->messageManager->addError($e->getMessage());
  33. } catch (\Exception $e) {
  34. $this->messageManager->addError(__('Something went wrong deleting this rate.'));
  35. }
  36. if ($this->getRequest()->getServer('HTTP_REFERER')) {
  37. $resultRedirect->setRefererUrl();
  38. } else {
  39. $resultRedirect->setPath("*/*/");
  40. }
  41. return $resultRedirect;
  42. }
  43. }
  44. }