Config.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * This file is part of the Klarna Core module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. /**
  11. * Configuration paths storage
  12. *
  13. * @author Magento Core Team <core@magentocommerce.com>
  14. */
  15. namespace Klarna\Core\Model;
  16. use Magento\Framework\App\Config\ScopeConfigInterface;
  17. use Magento\Store\Api\Data\StoreInterface;
  18. use Magento\Store\Model\ScopeInterface;
  19. use Magento\Store\Model\Store;
  20. /**
  21. * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  22. */
  23. class Config
  24. {
  25. const CONFIG_XML_PATH_KLARNA_DEBUG = 'klarna/api/debug';
  26. const CONFIG_XML_PATH_KLARNA_TEST_MODE = 'klarna/api/test_mode';
  27. const CONFIG_XML_PATH_GENERAL_STORE_INFORMATION_COUNTRY = 'general/store_information/country_id';
  28. const CONFIG_XML_PATH_GENERAL_STATE_OPTIONS = 'general/region/state_required';
  29. /**
  30. * Core store config
  31. *
  32. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  33. */
  34. private $scopeConfig;
  35. /**
  36. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  37. */
  38. public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
  39. {
  40. $this->scopeConfig = $scopeConfig;
  41. }
  42. /**
  43. * Check what taxes should be applied after discount
  44. *
  45. * @param null|string|bool|int|Store $store
  46. * @return bool
  47. */
  48. public function storeAddressSet($store = null)
  49. {
  50. return (bool)$this->scopeConfig->getValue(
  51. self::CONFIG_XML_PATH_GENERAL_STORE_INFORMATION_COUNTRY,
  52. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  53. $store
  54. );
  55. }
  56. /**
  57. * Get configuration setting "Apply Discount On Prices Including Tax" value
  58. *
  59. * @param null|string|bool|int|Store $store
  60. * @return bool
  61. */
  62. public function debugModeWhileLive($store = null)
  63. {
  64. if ($this->testMode($store)) {
  65. return false;
  66. }
  67. return $this->debugMode($store);
  68. }
  69. /**
  70. * Get defined tax calculation algorithm
  71. *
  72. * @param null|string|bool|int|Store $store
  73. * @return string
  74. */
  75. public function testMode($store = null)
  76. {
  77. return $this->scopeConfig->isSetFlag(
  78. self::CONFIG_XML_PATH_KLARNA_TEST_MODE,
  79. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  80. $store
  81. );
  82. }
  83. /**
  84. * Get tax class id specified for shipping tax estimation
  85. *
  86. * @param null|string|bool|int|Store $store
  87. * @return int
  88. */
  89. public function debugMode($store = null)
  90. {
  91. return $this->scopeConfig->isSetFlag(
  92. self::CONFIG_XML_PATH_KLARNA_DEBUG,
  93. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  94. $store
  95. );
  96. }
  97. /**
  98. * Return a list of countries that incorrectly have the state/region marked as required
  99. *
  100. * @return array
  101. */
  102. public function requiredRegions()
  103. {
  104. $failed = [];
  105. $knownCountriesWithOptionalRegion = [
  106. 'at',
  107. 'de',
  108. 'fi',
  109. ];
  110. $countries = $this->scopeConfig->getValue(self::CONFIG_XML_PATH_GENERAL_STATE_OPTIONS);
  111. $countries = explode(',', $countries);
  112. foreach ($knownCountriesWithOptionalRegion as $country) {
  113. if (in_array($country, $countries)) {
  114. $failed[] = $country;
  115. }
  116. }
  117. return $failed;
  118. }
  119. /**
  120. * Determine if a Klarna Payment method is enabled
  121. *
  122. * @param StoreInterface $store
  123. * @return bool
  124. * @SuppressWarnings(PMD.UnusedFormalParameter)
  125. */
  126. public function klarnaEnabled($store = null)
  127. {
  128. // It is expected that this method will have plugins added by other modules. $store is required in those cases.
  129. return false;
  130. }
  131. }