Rate.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Controller\Adminhtml;
  7. use Magento\Framework\Controller\ResultFactory;
  8. /**
  9. * Adminhtml tax rate controller
  10. *
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. */
  13. abstract class Rate extends \Magento\Backend\App\Action
  14. {
  15. /**
  16. * Authorization level of a basic admin session
  17. *
  18. * @see _isAllowed()
  19. */
  20. const ADMIN_RESOURCE = 'Magento_Tax::manage_tax';
  21. /**
  22. * @var \Magento\Framework\Registry
  23. */
  24. protected $_coreRegistry;
  25. /**
  26. * @var \Magento\Tax\Model\Calculation\Rate\Converter
  27. */
  28. protected $_taxRateConverter;
  29. /**
  30. * @var \Magento\Tax\Api\TaxRateRepositoryInterface
  31. */
  32. protected $_taxRateRepository;
  33. /**
  34. * @param \Magento\Backend\App\Action\Context $context
  35. * @param \Magento\Framework\Registry $coreRegistry
  36. * @param \Magento\Tax\Model\Calculation\Rate\Converter $taxRateConverter
  37. * @param \Magento\Tax\Api\TaxRateRepositoryInterface $taxRateRepository
  38. */
  39. public function __construct(
  40. \Magento\Backend\App\Action\Context $context,
  41. \Magento\Framework\Registry $coreRegistry,
  42. \Magento\Tax\Model\Calculation\Rate\Converter $taxRateConverter,
  43. \Magento\Tax\Api\TaxRateRepositoryInterface $taxRateRepository
  44. ) {
  45. $this->_coreRegistry = $coreRegistry;
  46. $this->_taxRateConverter = $taxRateConverter;
  47. $this->_taxRateRepository = $taxRateRepository;
  48. parent::__construct($context);
  49. }
  50. /**
  51. * Validate/Filter Rate Data
  52. *
  53. * @param array $rateData
  54. * @return array
  55. */
  56. protected function _processRateData($rateData)
  57. {
  58. $result = [];
  59. foreach ($rateData as $key => $value) {
  60. if (is_array($value)) {
  61. $result[$key] = $this->_processRateData($value);
  62. } else {
  63. $result[$key] = trim($value);
  64. }
  65. }
  66. return $result;
  67. }
  68. /**
  69. * Initialize action
  70. *
  71. * @return \Magento\Backend\Model\View\Result\Page
  72. */
  73. protected function initResultPage()
  74. {
  75. $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
  76. $resultPage->setActiveMenu('Magento_Tax::sales_tax_rates')
  77. ->addBreadcrumb(__('Sales'), __('Sales'))
  78. ->addBreadcrumb(__('Tax'), __('Tax'));
  79. return $resultPage;
  80. }
  81. }