Rule.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Tax rule controller
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Tax\Controller\Adminhtml;
  12. use Magento\Backend\App\Action;
  13. use Magento\Framework\Controller\ResultFactory;
  14. abstract class Rule extends \Magento\Backend\App\Action
  15. {
  16. /**
  17. * Authorization level of a basic admin session
  18. *
  19. * @see _isAllowed()
  20. */
  21. const ADMIN_RESOURCE = 'Magento_Tax::manage_tax';
  22. /**
  23. * Core registry
  24. *
  25. * @var \Magento\Framework\Registry
  26. */
  27. protected $_coreRegistry = null;
  28. /**
  29. * @var \Magento\Tax\Api\TaxRuleRepositoryInterface
  30. */
  31. protected $ruleService;
  32. /**
  33. * @var \Magento\Tax\Api\Data\TaxRuleInterfaceFactory
  34. */
  35. protected $taxRuleDataObjectFactory;
  36. /**
  37. * @param \Magento\Backend\App\Action\Context $context
  38. * @param \Magento\Framework\Registry $coreRegistry
  39. * @param \Magento\Tax\Api\TaxRuleRepositoryInterface $ruleService
  40. * @param \Magento\Tax\Api\Data\TaxRuleInterfaceFactory $taxRuleDataObjectFactory
  41. */
  42. public function __construct(
  43. \Magento\Backend\App\Action\Context $context,
  44. \Magento\Framework\Registry $coreRegistry,
  45. \Magento\Tax\Api\TaxRuleRepositoryInterface $ruleService,
  46. \Magento\Tax\Api\Data\TaxRuleInterfaceFactory $taxRuleDataObjectFactory
  47. ) {
  48. $this->_coreRegistry = $coreRegistry;
  49. $this->ruleService = $ruleService;
  50. $this->taxRuleDataObjectFactory = $taxRuleDataObjectFactory;
  51. parent::__construct($context);
  52. }
  53. /**
  54. * Initialize action
  55. *
  56. * @return \Magento\Backend\Model\View\Result\Page
  57. */
  58. protected function initResultPage()
  59. {
  60. $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
  61. $resultPage->setActiveMenu('Magento_Tax::sales_tax_rules')
  62. ->addBreadcrumb(__('Tax'), __('Tax'))
  63. ->addBreadcrumb(__('Tax Rules'), __('Tax Rules'));
  64. return $resultPage;
  65. }
  66. /**
  67. * Initialize tax rule service object with form data.
  68. *
  69. * @param array $postData
  70. * @return \Magento\Tax\Api\Data\TaxRuleInterface
  71. * @SuppressWarnings(PHPMD.NPathComplexity)
  72. */
  73. protected function populateTaxRule($postData)
  74. {
  75. $taxRule = $this->taxRuleDataObjectFactory->create();
  76. if (isset($postData['tax_calculation_rule_id'])) {
  77. $taxRule->setId($postData['tax_calculation_rule_id']);
  78. }
  79. if (isset($postData['code'])) {
  80. $taxRule->setCode($postData['code']);
  81. }
  82. if (isset($postData['tax_rate'])) {
  83. $taxRule->setTaxRateIds($postData['tax_rate']);
  84. }
  85. if (isset($postData['tax_customer_class'])) {
  86. $taxRule->setCustomerTaxClassIds($postData['tax_customer_class']);
  87. }
  88. if (isset($postData['tax_product_class'])) {
  89. $taxRule->setProductTaxClassIds($postData['tax_product_class']);
  90. }
  91. if (isset($postData['priority'])) {
  92. $taxRule->setPriority($postData['priority']);
  93. }
  94. if (isset($postData['calculate_subtotal'])) {
  95. $taxRule->setCalculateSubtotal($postData['calculate_subtotal']);
  96. }
  97. if (isset($postData['position'])) {
  98. $taxRule->setPosition($postData['position']);
  99. }
  100. return $taxRule;
  101. }
  102. }