Shipping.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Block\Cart;
  7. /**
  8. * @api
  9. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  10. * @since 100.0.2
  11. */
  12. class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
  13. {
  14. /**
  15. * @var \Magento\Checkout\Model\CompositeConfigProvider
  16. */
  17. protected $configProvider;
  18. /**
  19. * @var array|\Magento\Checkout\Block\Checkout\LayoutProcessorInterface[]
  20. */
  21. protected $layoutProcessors;
  22. /**
  23. * @var \Magento\Framework\Serialize\Serializer\Json
  24. */
  25. private $serializer;
  26. /**
  27. * @param \Magento\Framework\View\Element\Template\Context $context
  28. * @param \Magento\Customer\Model\Session $customerSession
  29. * @param \Magento\Checkout\Model\Session $checkoutSession
  30. * @param \Magento\Checkout\Model\CompositeConfigProvider $configProvider
  31. * @param array $layoutProcessors
  32. * @param array $data
  33. * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
  34. * @throws \RuntimeException
  35. */
  36. public function __construct(
  37. \Magento\Framework\View\Element\Template\Context $context,
  38. \Magento\Customer\Model\Session $customerSession,
  39. \Magento\Checkout\Model\Session $checkoutSession,
  40. \Magento\Checkout\Model\CompositeConfigProvider $configProvider,
  41. array $layoutProcessors = [],
  42. array $data = [],
  43. \Magento\Framework\Serialize\Serializer\Json $serializer = null
  44. ) {
  45. $this->configProvider = $configProvider;
  46. $this->layoutProcessors = $layoutProcessors;
  47. parent::__construct($context, $customerSession, $checkoutSession, $data);
  48. $this->_isScopePrivate = true;
  49. $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
  50. ->get(\Magento\Framework\Serialize\Serializer\Json::class);
  51. }
  52. /**
  53. * Retrieve checkout configuration
  54. *
  55. * @return array
  56. * @codeCoverageIgnore
  57. */
  58. public function getCheckoutConfig()
  59. {
  60. return $this->configProvider->getConfig();
  61. }
  62. /**
  63. * Retrieve serialized JS layout configuration ready to use in template
  64. *
  65. * @return string
  66. */
  67. public function getJsLayout()
  68. {
  69. foreach ($this->layoutProcessors as $processor) {
  70. $this->jsLayout = $processor->process($this->jsLayout);
  71. }
  72. return json_encode($this->jsLayout, JSON_HEX_TAG);
  73. }
  74. /**
  75. * Get base url for block.
  76. *
  77. * @return string
  78. * @codeCoverageIgnore
  79. */
  80. public function getBaseUrl()
  81. {
  82. return $this->_storeManager->getStore()->getBaseUrl();
  83. }
  84. /**
  85. * @return bool|string
  86. * @since 100.2.0
  87. */
  88. public function getSerializedCheckoutConfig()
  89. {
  90. return json_encode($this->getCheckoutConfig(), JSON_HEX_TAG);
  91. }
  92. }