CollectorPlugin.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Checkout\Orderline;
  11. use Klarna\Core\Model\Checkout\Orderline\Collector;
  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 CollectorPlugin
  18. *
  19. * @package Klarna\Kp\Plugin\Model\Checkout\Orderline
  20. */
  21. class CollectorPlugin
  22. {
  23. /**
  24. * @var ScopeConfigInterface
  25. */
  26. private $config;
  27. /**
  28. * CollectorPlugin constructor.
  29. *
  30. * @param ScopeConfigInterface $config
  31. */
  32. public function __construct(ScopeConfigInterface $config)
  33. {
  34. $this->config = $config;
  35. }
  36. /**
  37. * @param Collector $subject
  38. * @param bool $result
  39. * @param StoreInterface $store
  40. * @return bool
  41. * @SuppressWarnings(PMD.UnusedFormalParameter)
  42. */
  43. public function afterIsKlarnaActive(Collector $subject, $result, $store)
  44. {
  45. if ($result) {
  46. return $result; // No need to check any further, someone already said yes (true)
  47. }
  48. return $this->config->isSetFlag(
  49. sprintf('payment/%s/active', Kp::METHOD_CODE),
  50. ScopeInterface::SCOPE_STORES,
  51. $store
  52. );
  53. }
  54. }