TaxOverride.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\Config\Backend;
  7. use Magento\Framework\App\Cache\TypeListInterface;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\App\Config\Value;
  10. use Magento\Framework\Data\Collection\AbstractDb;
  11. use Magento\Framework\Model\Context;
  12. use Magento\Framework\Model\ResourceModel\AbstractResource;
  13. use Magento\Framework\Registry;
  14. use Vertex\Tax\Model\Config\DeliveryTerm;
  15. /**
  16. * Config model for Tax Override
  17. */
  18. class TaxOverride extends Value
  19. {
  20. /** @var DeliveryTerm */
  21. private $deliveryTermConfig;
  22. /**
  23. * @param Context $context
  24. * @param Registry $registry
  25. * @param ScopeConfigInterface $config
  26. * @param TypeListInterface $cacheTypeList
  27. * @param DeliveryTerm $deliveryTermConfig
  28. * @param AbstractResource|null $resource
  29. * @param AbstractDb|null $resourceCollection
  30. * @param array $data
  31. */
  32. public function __construct(
  33. Context $context,
  34. Registry $registry,
  35. ScopeConfigInterface $config,
  36. TypeListInterface $cacheTypeList,
  37. DeliveryTerm $deliveryTermConfig,
  38. AbstractResource $resource = null,
  39. AbstractDb $resourceCollection = null,
  40. array $data = []
  41. ) {
  42. parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
  43. $this->deliveryTermConfig = $deliveryTermConfig;
  44. }
  45. /**
  46. * Unserialize the value loaded from the database
  47. *
  48. * @return $this
  49. */
  50. protected function _afterLoad()
  51. {
  52. $value = $this->deliveryTermConfig->makeArrayFieldValue($this->getValue());
  53. $this->setValue($value);
  54. return $this;
  55. }
  56. /**
  57. * Serialize the value before it is saved to the database
  58. *
  59. * @return $this
  60. */
  61. public function beforeSave()
  62. {
  63. $value = $this->deliveryTermConfig->makeStorableArrayFieldValue($this->getValue());
  64. $this->setValue($value);
  65. return $this;
  66. }
  67. }