IgnoreTaxNotification.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Tax;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\Controller\ResultFactory;
  10. class IgnoreTaxNotification extends \Magento\Tax\Controller\Adminhtml\Tax
  11. {
  12. /**
  13. * @var \Magento\Framework\App\Cache\TypeListInterface
  14. */
  15. protected $_cacheTypeList;
  16. /**
  17. * @param \Magento\Backend\App\Action\Context $context
  18. * @param \Magento\Tax\Api\TaxClassRepositoryInterface $taxClassService
  19. * @param \Magento\Tax\Api\Data\TaxClassInterfaceFactory $taxClassDataObjectFactory
  20. * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  21. */
  22. public function __construct(
  23. \Magento\Backend\App\Action\Context $context,
  24. \Magento\Tax\Api\TaxClassRepositoryInterface $taxClassService,
  25. \Magento\Tax\Api\Data\TaxClassInterfaceFactory $taxClassDataObjectFactory,
  26. \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  27. ) {
  28. $this->_cacheTypeList = $cacheTypeList;
  29. parent::__construct($context, $taxClassService, $taxClassDataObjectFactory);
  30. }
  31. /**
  32. * Set tax ignore notification flag and redirect back
  33. *
  34. * @return \Magento\Backend\Model\View\Result\Redirect
  35. */
  36. public function execute()
  37. {
  38. $section = $this->getRequest()->getParam('section');
  39. if ($section) {
  40. try {
  41. $path = 'tax/notification/ignore_' . $section;
  42. $this->_objectManager->get(\Magento\Config\Model\ResourceModel\Config::class)
  43. ->saveConfig($path, 1, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
  44. } catch (\Exception $e) {
  45. $this->messageManager->addError($e->getMessage());
  46. }
  47. }
  48. // clear the block html cache
  49. $this->_cacheTypeList->cleanType('config');
  50. $this->_eventManager->dispatch('adminhtml_cache_refresh_type', ['type' => 'config']);
  51. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  52. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  53. return $resultRedirect->setRefererUrl();
  54. }
  55. }