Skip to content

Commit f00020a

Browse files
author
Yuri Kovsher
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-36110' into MAGETWO-36610
2 parents c90c2a3 + 6f7e6a9 commit f00020a

File tree

18 files changed

+212
-223
lines changed

18 files changed

+212
-223
lines changed

app/code/Magento/Tax/Controller/Adminhtml/Rate.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Tax\Controller\Adminhtml;
88

9+
use Magento\Framework\Controller\ResultFactory;
10+
911
/**
1012
* Adminhtml tax rate controller
1113
*
@@ -76,21 +78,15 @@ protected function _processRateData($rateData)
7678
/**
7779
* Initialize action
7880
*
79-
* @return \Magento\Backend\App\Action
81+
* @return \Magento\Backend\Model\View\Result\Page
8082
*/
81-
protected function _initAction()
83+
protected function initResultPage()
8284
{
83-
$this->_view->loadLayout();
84-
$this->_setActiveMenu(
85-
'Magento_Tax::sales_tax_rates'
86-
)->_addBreadcrumb(
87-
__('Sales'),
88-
__('Sales')
89-
)->_addBreadcrumb(
90-
__('Tax'),
91-
__('Tax')
92-
);
93-
return $this;
85+
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
86+
$resultPage->setActiveMenu('Magento_Tax::sales_tax_rates')
87+
->addBreadcrumb(__('Sales'), __('Sales'))
88+
->addBreadcrumb(__('Tax'), __('Tax'));
89+
return $resultPage;
9490
}
9591

9692
/**

app/code/Magento/Tax/Controller/Adminhtml/Rate/Add.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Add extends \Magento\Tax\Controller\Adminhtml\Rate
1313
/**
1414
* Show Add Form
1515
*
16-
* @return void
16+
* @return \Magento\Backend\Model\View\Result\Page
1717
*/
1818
public function execute()
1919
{
@@ -22,26 +22,18 @@ public function execute()
2222
$this->_objectManager->get('Magento\Backend\Model\Session')->getFormData(true)
2323
);
2424

25-
$this->_initAction()->_addBreadcrumb(
26-
__('Manage Tax Rates'),
27-
__('Manage Tax Rates'),
28-
$this->getUrl('tax/rate')
29-
)->_addBreadcrumb(
30-
__('New Tax Rate'),
31-
__('New Tax Rate')
32-
)->_addContent(
33-
$this->_view->getLayout()->createBlock(
34-
'Magento\Tax\Block\Adminhtml\Rate\Toolbar\Save'
35-
)->assign(
36-
'header',
37-
__('Add New Tax Rate')
38-
)->assign(
39-
'form',
40-
$this->_view->getLayout()->createBlock('Magento\Tax\Block\Adminhtml\Rate\Form', 'tax_rate_form')
41-
)
42-
);
43-
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Tax Zones and Rates'));
44-
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('New Tax Rate'));
45-
$this->_view->renderLayout();
25+
$resultPage = $this->initResultPage();
26+
$layout = $resultPage->getLayout();
27+
$toolbarSaveBlock = $layout->createBlock('Magento\Tax\Block\Adminhtml\Rate\Toolbar\Save')
28+
->assign('header', __('Add New Tax Rate'))
29+
->assign('form', $layout->createBlock('Magento\Tax\Block\Adminhtml\Rate\Form', 'tax_rate_form'));
30+
31+
$resultPage->addBreadcrumb(__('Manage Tax Rates'), __('Manage Tax Rates'), $this->getUrl('tax/rate'))
32+
->addBreadcrumb(__('New Tax Rate'), __('New Tax Rate'))
33+
->addContent($toolbarSaveBlock);
34+
35+
$resultPage->getConfig()->getTitle()->prepend(__('Tax Zones and Rates'));
36+
$resultPage->getConfig()->getTitle()->prepend(__('New Tax Rate'));
37+
return $resultPage;
4638
}
4739
}

app/code/Magento/Tax/Controller/Adminhtml/Rate/AjaxDelete.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,33 @@
66
*/
77
namespace Magento\Tax\Controller\Adminhtml\Rate;
88

9+
use Magento\Framework\Controller\ResultFactory;
10+
911
class AjaxDelete extends \Magento\Tax\Controller\Adminhtml\Rate
1012
{
1113
/**
1214
* Delete Tax Rate via AJAX
1315
*
14-
* @return void
16+
* @return \Magento\Framework\Controller\Result\Json
1517
*/
1618
public function execute()
1719
{
1820
$rateId = (int)$this->getRequest()->getParam('tax_calculation_rate_id');
1921
try {
2022
$this->_taxRateRepository->deleteById($rateId);
21-
$responseContent = $this->_objectManager->get(
22-
'Magento\Framework\Json\Helper\Data'
23-
)->jsonEncode(
24-
['success' => true, 'error_message' => '']
25-
);
23+
$responseContent = ['success' => true, 'error_message' => ''];
2624
} catch (\Magento\Framework\Exception\LocalizedException $e) {
27-
$responseContent = $this->_objectManager->get(
28-
'Magento\Framework\Json\Helper\Data'
29-
)->jsonEncode(
30-
['success' => false, 'error_message' => $e->getMessage()]
31-
);
25+
$responseContent = ['success' => false, 'error_message' => $e->getMessage()];
3226
} catch (\Exception $e) {
33-
$responseContent = $this->_objectManager->get(
34-
'Magento\Framework\Json\Helper\Data'
35-
)->jsonEncode(
36-
['success' => false, 'error_message' => __('An error occurred while deleting this tax rate.')]
37-
);
27+
$responseContent = [
28+
'success' => false,
29+
'error_message' => __('An error occurred while deleting this tax rate.')
30+
];
3831
}
39-
$this->getResponse()->representJson($responseContent);
32+
33+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
34+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
35+
$resultJson->setData($responseContent);
36+
return $resultJson;
4037
}
4138
}

app/code/Magento/Tax/Controller/Adminhtml/Rate/AjaxSave.php

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,47 @@
66
*/
77
namespace Magento\Tax\Controller\Adminhtml\Rate;
88

9+
use Magento\Framework\Controller\ResultFactory;
10+
911
class AjaxSave extends \Magento\Tax\Controller\Adminhtml\Rate
1012
{
1113
/**
1214
* Save Tax Rate via AJAX
1315
*
14-
* @return void
16+
* @return \Magento\Framework\Controller\Result\Json
1517
*/
1618
public function execute()
1719
{
18-
$responseContent = '';
1920
try {
2021
$rateData = $this->_processRateData($this->getRequest()->getPostValue());
2122
/** @var \Magento\Tax\Api\Data\TaxRateInterface $taxRate */
2223
$taxRate = $this->populateTaxRateData($rateData);
2324
$this->_taxRateRepository->save($taxRate);
24-
$responseContent = $this->_objectManager->get(
25-
'Magento\Framework\Json\Helper\Data'
26-
)->jsonEncode(
27-
[
28-
'success' => true,
29-
'error_message' => '',
30-
'tax_calculation_rate_id' => $taxRate->getId(),
31-
'code' => $taxRate->getCode(),
32-
]
33-
);
25+
$responseContent = [
26+
'success' => true,
27+
'error_message' => '',
28+
'tax_calculation_rate_id' => $taxRate->getId(),
29+
'code' => $taxRate->getCode(),
30+
];
3431
} catch (\Magento\Framework\Exception\LocalizedException $e) {
35-
$responseContent = $this->_objectManager->get(
36-
'Magento\Framework\Json\Helper\Data'
37-
)->jsonEncode(
38-
[
39-
'success' => false,
40-
'error_message' => $e->getMessage(),
41-
'tax_calculation_rate_id' => '',
42-
'code' => '',
43-
]
44-
);
32+
$responseContent = [
33+
'success' => false,
34+
'error_message' => $e->getMessage(),
35+
'tax_calculation_rate_id' => '',
36+
'code' => '',
37+
];
4538
} catch (\Exception $e) {
46-
$responseContent = $this->_objectManager->get(
47-
'Magento\Framework\Json\Helper\Data'
48-
)->jsonEncode(
49-
[
50-
'success' => false,
51-
'error_message' => __('Something went wrong saving this rate.'),
52-
'tax_calculation_rate_id' => '',
53-
'code' => '',
54-
]
55-
);
39+
$responseContent = [
40+
'success' => false,
41+
'error_message' => __('Something went wrong saving this rate.'),
42+
'tax_calculation_rate_id' => '',
43+
'code' => '',
44+
];
5645
}
57-
$this->getResponse()->representJson($responseContent);
46+
47+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
48+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
49+
$resultJson->setData($responseContent);
50+
return $resultJson;
5851
}
5952
}

app/code/Magento/Tax/Controller/Adminhtml/Rate/Delete.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Tax\Controller\Adminhtml\Rate;
88

99
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Controller\ResultFactory;
1011

1112
class Delete extends \Magento\Tax\Controller\Adminhtml\Rate
1213
{
@@ -18,20 +19,19 @@ class Delete extends \Magento\Tax\Controller\Adminhtml\Rate
1819
public function execute()
1920
{
2021
if ($rateId = $this->getRequest()->getParam('rate')) {
22+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
23+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
2124
try {
2225
$this->_taxRateRepository->deleteById($rateId);
2326

2427
$this->messageManager->addSuccess(__('The tax rate has been deleted.'));
25-
$this->getResponse()->setRedirect($this->getUrl("*/*/"));
26-
return;
28+
return $resultRedirect->setPath("*/*/");
2729
} catch (NoSuchEntityException $e) {
2830
$this->messageManager->addError(
2931
__('Something went wrong deleting this rate because of an incorrect rate ID.')
3032
);
31-
$this->getResponse()->setRedirect($this->getUrl('tax/*/'));
32-
return;
33+
return $resultRedirect->setPath("tax/*/");
3334
}
34-
return $this->getDefaultResult();
3535
}
3636
}
3737

@@ -42,11 +42,11 @@ public function execute()
4242
*/
4343
public function getDefaultResult()
4444
{
45-
$resultRedirect = $this->resultRedirectFactory->create();
45+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
4646
if ($this->getRequest()->getServer('HTTP_REFERER')) {
4747
$resultRedirect->setRefererUrl();
4848
} else {
49-
$resultRedirect->setUrl($this->getUrl("*/*/"));
49+
$resultRedirect->setPath("*/*/");
5050
}
5151
return $resultRedirect;
5252
}

app/code/Magento/Tax/Controller/Adminhtml/Rate/Edit.php

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
use Magento\Framework\Exception\NoSuchEntityException;
1010
use Magento\Tax\Controller\RegistryConstants;
11+
use Magento\Framework\Controller\ResultFactory;
1112

1213
class Edit extends \Magento\Tax\Controller\Adminhtml\Rate
1314
{
1415
/**
1516
* Show Edit Form
1617
*
17-
* @return void
18+
* @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
1819
*/
1920
public function execute()
2021
{
@@ -23,35 +24,27 @@ public function execute()
2324
try {
2425
$taxRateDataObject = $this->_taxRateRepository->get($rateId);
2526
} catch (NoSuchEntityException $e) {
26-
$this->getResponse()->setRedirect($this->getUrl("*/*/"));
27-
return;
27+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
28+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
29+
return $resultRedirect->setPath("*/*/");
2830
}
2931

30-
$this->_initAction()->_addBreadcrumb(
31-
__('Manage Tax Rates'),
32-
__('Manage Tax Rates'),
33-
$this->getUrl('tax/rate')
34-
)->_addBreadcrumb(
35-
__('Edit Tax Rate'),
36-
__('Edit Tax Rate')
37-
)->_addContent(
38-
$this->_view->getLayout()->createBlock(
39-
'Magento\Tax\Block\Adminhtml\Rate\Toolbar\Save'
40-
)->assign(
41-
'header',
42-
__('Edit Tax Rate')
43-
)->assign(
32+
$resultPage = $this->initResultPage();
33+
$layout = $resultPage->getLayout();
34+
35+
$toolbarSaveBlock = $layout->createBlock('Magento\Tax\Block\Adminhtml\Rate\Toolbar\Save')
36+
->assign('header', __('Edit Tax Rate'))
37+
->assign(
4438
'form',
45-
$this->_view->getLayout()->createBlock(
46-
'Magento\Tax\Block\Adminhtml\Rate\Form',
47-
'tax_rate_form'
48-
)->setShowLegend(
49-
true
50-
)
51-
)
52-
);
53-
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Tax Zones and Rates'));
54-
$this->_view->getPage()->getConfig()->getTitle()->prepend(sprintf("%s", $taxRateDataObject->getCode()));
55-
$this->_view->renderLayout();
39+
$layout->createBlock('Magento\Tax\Block\Adminhtml\Rate\Form', 'tax_rate_form')->setShowLegend(true)
40+
);
41+
42+
$resultPage->addBreadcrumb(__('Manage Tax Rates'), __('Manage Tax Rates'), $this->getUrl('tax/rate'))
43+
->addBreadcrumb(__('Edit Tax Rate'), __('Edit Tax Rate'))
44+
->addContent($toolbarSaveBlock);
45+
46+
$resultPage->getConfig()->getTitle()->prepend(__('Tax Zones and Rates'));
47+
$resultPage->getConfig()->getTitle()->prepend(sprintf("%s", $taxRateDataObject->getCode()));
48+
return $resultPage;
5649
}
5750
}

app/code/Magento/Tax/Controller/Adminhtml/Rate/Index.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ class Index extends \Magento\Tax\Controller\Adminhtml\Rate
1111
/**
1212
* Show Main Grid
1313
*
14-
* @return void
14+
* @return \Magento\Backend\Model\View\Result\Page
1515
*/
1616
public function execute()
1717
{
18-
$this->_initAction()->_addBreadcrumb(__('Manage Tax Rates'), __('Manage Tax Rates'));
19-
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Tax Zones and Rates'));
20-
$this->_view->renderLayout();
18+
$resultPage = $this->initResultPage();
19+
$resultPage->addBreadcrumb(__('Manage Tax Rates'), __('Manage Tax Rates'));
20+
$resultPage->getConfig()->getTitle()->prepend(__('Tax Zones and Rates'));
21+
return $resultPage;
2122
}
2223
}

app/code/Magento/Tax/Controller/Adminhtml/Rate/Save.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
namespace Magento\Tax\Controller\Adminhtml\Rate;
88

99
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Controller\ResultFactory;
1011

1112
class Save extends \Magento\Tax\Controller\Adminhtml\Rate
1213
{
1314
/**
1415
* Save Rate and Data
1516
*
16-
* @return void
17+
* @return \Magento\Backend\Model\View\Result\Redirect
1718
*/
1819
public function execute()
1920
{
21+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
22+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
2023
$ratePost = $this->getRequest()->getPostValue();
2124
if ($ratePost) {
2225
$rateId = $this->getRequest()->getParam('tax_calculation_rate_id');
@@ -33,18 +36,15 @@ public function execute()
3336
$this->_taxRateRepository->save($taxData);
3437

3538
$this->messageManager->addSuccess(__('The tax rate has been saved.'));
36-
$this->getResponse()->setRedirect($this->getUrl("*/*/"));
37-
return;
39+
return $resultRedirect->setPath('*/*/');
3840
} catch (\Magento\Framework\Exception\LocalizedException $e) {
3941
$this->_objectManager->get('Magento\Backend\Model\Session')->setFormData($ratePost);
4042
$this->messageManager->addError($e->getMessage());
4143
} catch (\Exception $e) {
4244
$this->messageManager->addError($e->getMessage());
4345
}
44-
45-
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*')));
46-
return;
46+
return $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*')));
4747
}
48-
$this->getResponse()->setRedirect($this->getUrl('tax/rate'));
48+
return $resultRedirect->setPath('tax/rate');
4949
}
5050
}

0 commit comments

Comments
 (0)