ConfigPlugin.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * This file is part of the Klarna Kp module
  4. *
  5. * (c) Klarna AB
  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. namespace Klarna\Kp\Plugin\Model;
  11. use Klarna\Core\Model\Config;
  12. use Klarna\Kp\Model\Payment\Kp;
  13. use Magento\Framework\App\Config\ScopeConfigInterface;
  14. use Magento\Store\Api\Data\StoreInterface;
  15. use Magento\Store\Model\ScopeInterface;
  16. /**
  17. * Class ConfigPlugin
  18. *
  19. * @package Klarna\Kp\Plugin\Model
  20. */
  21. class ConfigPlugin
  22. {
  23. /**
  24. * @var ScopeConfigInterface
  25. */
  26. private $config;
  27. /**
  28. * ConfigPlugin constructor.
  29. *
  30. * @param ScopeConfigInterface $config
  31. */
  32. public function __construct(ScopeConfigInterface $config)
  33. {
  34. $this->config = $config;
  35. }
  36. /**
  37. * @param Config $subject
  38. * @param bool $result
  39. * @param StoreInterface $store
  40. * @return bool
  41. * @SuppressWarnings(PMD.UnusedFormalParameter)
  42. */
  43. public function afterKlarnaEnabled(Config $subject, $result, $store = null)
  44. {
  45. if ($result) {
  46. return $result; // No need to check any further, someone already said yes (true)
  47. }
  48. $scope = ($store === null ? ScopeConfigInterface::SCOPE_TYPE_DEFAULT : ScopeInterface::SCOPE_STORES);
  49. return $this->config->isSetFlag(
  50. sprintf('payment/%s/active', Kp::METHOD_CODE),
  51. $scope,
  52. $store
  53. );
  54. }
  55. }