OnepagePlugin.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\Checkout\Block;
  11. use Klarna\Kp\Model\Payment\Kp;
  12. use Klarna\Kp\Model\Session as KlarnaKpSession;
  13. use Magento\Framework\App\Config\ScopeConfigInterface;
  14. use Magento\Store\Model\ScopeInterface;
  15. use Magento\Store\Model\StoreManagerInterface;
  16. /**
  17. * This onepage checkout block run before or after specific actions of the magento onepage checkout block
  18. *
  19. * @package Klarna\Kp\Plugin\Checkout\Block
  20. */
  21. class OnepagePlugin
  22. {
  23. /**
  24. * @var KlarnaKpSession
  25. */
  26. private $kpSession;
  27. /**
  28. * @var ScopeConfigInterface
  29. */
  30. private $config;
  31. /** @var StoreManagerInterface */
  32. private $storeManager;
  33. /**
  34. * OnepagePlugin constructor.
  35. *
  36. * @param KlarnaKpSession $kpSession
  37. * @param ScopeConfigInterface $config
  38. * @param StoreManagerInterface $storeManager
  39. */
  40. public function __construct(
  41. KlarnaKpSession $kpSession,
  42. ScopeConfigInterface $config,
  43. StoreManagerInterface $storeManager
  44. ) {
  45. $this->kpSession = $kpSession;
  46. $this->config = $config;
  47. $this->storeManager = $storeManager;
  48. }
  49. /**
  50. * Initialize Klarna Payment session before get js layout
  51. *
  52. * @throws \Klarna\Core\Exception
  53. * @throws \Klarna\Core\Model\Api\Exception
  54. */
  55. public function beforeGetJsLayout()
  56. {
  57. $store = $this->storeManager->getStore();
  58. if ($this->config->isSetFlag(
  59. sprintf('payment/%s/active', Kp::METHOD_CODE),
  60. ScopeInterface::SCOPE_STORES,
  61. $store
  62. )) {
  63. $this->kpSession->init();
  64. }
  65. }
  66. }