/
Delete.php
48 lines (44 loc) · 1.7 KB
/
Delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Tax\Controller\Adminhtml\Rate;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Controller\ResultFactory;
class Delete extends \Magento\Tax\Controller\Adminhtml\Rate
{
/**
* Delete Rate and Data
*
* @return \Magento\Backend\Model\View\Result\Redirect|void
*/
public function execute()
{
if ($rateId = $this->getRequest()->getParam('rate')) {
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
try {
$this->_taxRateRepository->deleteById($rateId);
$this->messageManager->addSuccess(__('You deleted the tax rate.'));
return $resultRedirect->setPath("*/*/");
} catch (NoSuchEntityException $e) {
$this->messageManager->addError(
__('We can\'t delete this rate because of an incorrect rate ID.')
);
return $resultRedirect->setPath("tax/*/");
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('Something went wrong deleting this rate.'));
}
if ($this->getRequest()->getServer('HTTP_REFERER')) {
$resultRedirect->setRefererUrl();
} else {
$resultRedirect->setPath("*/*/");
}
return $resultRedirect;
}
}
}