Onepage.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Block;
  7. /**
  8. * Onepage checkout block
  9. * @api
  10. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  11. * @since 100.0.2
  12. */
  13. class Onepage extends \Magento\Framework\View\Element\Template
  14. {
  15. /**
  16. * @var \Magento\Framework\Data\Form\FormKey
  17. */
  18. protected $formKey;
  19. /**
  20. * @var bool
  21. */
  22. protected $_isScopePrivate = false;
  23. /**
  24. * @var array
  25. */
  26. protected $jsLayout;
  27. /**
  28. * @var \Magento\Checkout\Model\CompositeConfigProvider
  29. */
  30. protected $configProvider;
  31. /**
  32. * @var array|\Magento\Checkout\Block\Checkout\LayoutProcessorInterface[]
  33. */
  34. protected $layoutProcessors;
  35. /**
  36. * @var \Magento\Framework\Serialize\SerializerInterface
  37. */
  38. private $serializer;
  39. /**
  40. * @param \Magento\Framework\View\Element\Template\Context $context
  41. * @param \Magento\Framework\Data\Form\FormKey $formKey
  42. * @param \Magento\Checkout\Model\CompositeConfigProvider $configProvider
  43. * @param array $layoutProcessors
  44. * @param array $data
  45. * @param \Magento\Framework\Serialize\Serializer\Json $serializer
  46. * @param \Magento\Framework\Serialize\SerializerInterface $serializerInterface
  47. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  48. */
  49. public function __construct(
  50. \Magento\Framework\View\Element\Template\Context $context,
  51. \Magento\Framework\Data\Form\FormKey $formKey,
  52. \Magento\Checkout\Model\CompositeConfigProvider $configProvider,
  53. array $layoutProcessors = [],
  54. array $data = [],
  55. \Magento\Framework\Serialize\Serializer\Json $serializer = null,
  56. \Magento\Framework\Serialize\SerializerInterface $serializerInterface = null
  57. ) {
  58. parent::__construct($context, $data);
  59. $this->formKey = $formKey;
  60. $this->_isScopePrivate = true;
  61. $this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
  62. $this->configProvider = $configProvider;
  63. $this->layoutProcessors = $layoutProcessors;
  64. $this->serializer = $serializerInterface ?: \Magento\Framework\App\ObjectManager::getInstance()
  65. ->get(\Magento\Framework\Serialize\Serializer\JsonHexTag::class);
  66. }
  67. /**
  68. * @inheritdoc
  69. */
  70. public function getJsLayout()
  71. {
  72. foreach ($this->layoutProcessors as $processor) {
  73. $this->jsLayout = $processor->process($this->jsLayout);
  74. }
  75. return $this->serializer->serialize($this->jsLayout);
  76. }
  77. /**
  78. * Retrieve form key
  79. *
  80. * @return string
  81. * @codeCoverageIgnore
  82. */
  83. public function getFormKey()
  84. {
  85. return $this->formKey->getFormKey();
  86. }
  87. /**
  88. * Retrieve checkout configuration
  89. *
  90. * @return array
  91. * @codeCoverageIgnore
  92. */
  93. public function getCheckoutConfig()
  94. {
  95. return $this->configProvider->getConfig();
  96. }
  97. /**
  98. * Get base url for block.
  99. *
  100. * @return string
  101. * @codeCoverageIgnore
  102. */
  103. public function getBaseUrl()
  104. {
  105. return $this->_storeManager->getStore()->getBaseUrl();
  106. }
  107. /**
  108. * Retrieve serialized checkout config.
  109. *
  110. * @return bool|string
  111. * @since 100.2.0
  112. */
  113. public function getSerializedCheckoutConfig()
  114. {
  115. return $this->serializer->serialize($this->getCheckoutConfig());
  116. }
  117. }