Payment.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Order;
  7. use Magento\Payment\Model\Info;
  8. /**
  9. * Adminhtml sales order payment information
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class Payment extends \Magento\Backend\Block\Template
  16. {
  17. /**
  18. * Payment data
  19. *
  20. * @var \Magento\Payment\Helper\Data
  21. */
  22. protected $_paymentData = null;
  23. /**
  24. * @param \Magento\Backend\Block\Template\Context $context
  25. * @param \Magento\Payment\Helper\Data $paymentData
  26. * @param array $data
  27. */
  28. public function __construct(
  29. \Magento\Backend\Block\Template\Context $context,
  30. \Magento\Payment\Helper\Data $paymentData,
  31. array $data = []
  32. ) {
  33. $this->_paymentData = $paymentData;
  34. parent::__construct($context, $data);
  35. }
  36. /**
  37. * Retrieve required options from parent
  38. *
  39. * @return void
  40. * @throws \Magento\Framework\Exception\LocalizedException
  41. */
  42. protected function _beforeToHtml()
  43. {
  44. if (!$this->getParentBlock()) {
  45. throw new \Magento\Framework\Exception\LocalizedException(__('Invalid parent block for this block'));
  46. }
  47. $this->setPayment($this->getParentBlock()->getOrder()->getPayment());
  48. parent::_beforeToHtml();
  49. }
  50. /**
  51. * Set payment
  52. *
  53. * @param Info $payment
  54. * @return $this
  55. */
  56. public function setPayment($payment)
  57. {
  58. $paymentInfoBlock = $this->_paymentData->getInfoBlock($payment, $this->getLayout());
  59. $this->setChild('info', $paymentInfoBlock);
  60. $this->setData('payment', $payment);
  61. return $this;
  62. }
  63. /**
  64. * Prepare html output
  65. *
  66. * @return string
  67. */
  68. protected function _toHtml()
  69. {
  70. return $this->getChildHtml('info');
  71. }
  72. }