Notification.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Model\Config;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Tax\Model\Config;
  9. /**
  10. * Tax Config Notification
  11. */
  12. class Notification extends \Magento\Framework\App\Config\Value
  13. {
  14. /**
  15. * @var string
  16. */
  17. protected $_eventPrefix = 'tax_config_notification';
  18. /**
  19. * @var \Magento\Config\Model\ResourceModel\Config
  20. */
  21. protected $resourceConfig;
  22. /**
  23. * @param \Magento\Framework\Model\Context $context
  24. * @param \Magento\Framework\Registry $registry
  25. * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  26. * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  27. * @param \Magento\Config\Model\ResourceModel\Config $resourceConfig
  28. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  29. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  30. * @param array $data
  31. */
  32. public function __construct(
  33. \Magento\Framework\Model\Context $context,
  34. \Magento\Framework\Registry $registry,
  35. \Magento\Framework\App\Config\ScopeConfigInterface $config,
  36. \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
  37. \Magento\Config\Model\ResourceModel\Config $resourceConfig,
  38. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  39. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  40. array $data = []
  41. ) {
  42. $this->resourceConfig = $resourceConfig;
  43. parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
  44. }
  45. /**
  46. * Prepare and store cron settings after save
  47. *
  48. * @return $this
  49. */
  50. public function afterSave()
  51. {
  52. if ($this->isValueChanged()) {
  53. $this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT);
  54. $this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY);
  55. $this->_resetNotificationFlag(Config::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT);
  56. }
  57. return parent::afterSave();
  58. }
  59. /**
  60. * Reset flag for showing tax notifications
  61. *
  62. * @param string $path
  63. * @return \Magento\Tax\Model\Config\Notification
  64. */
  65. protected function _resetNotificationFlag($path)
  66. {
  67. $this->resourceConfig->saveConfig($path, 0, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
  68. return $this;
  69. }
  70. }