Grid.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Transactions\Detail;
  7. /**
  8. * Adminhtml transaction details grid
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
  15. {
  16. /**
  17. * Core registry
  18. *
  19. * @var \Magento\Framework\Registry
  20. */
  21. protected $_coreRegistry = null;
  22. /**
  23. * Collection factory
  24. *
  25. * @var \Magento\Framework\Data\CollectionFactory
  26. */
  27. protected $_collectionFactory;
  28. /**
  29. * @param \Magento\Backend\Block\Template\Context $context
  30. * @param \Magento\Backend\Helper\Data $backendHelper
  31. * @param \Magento\Framework\Data\CollectionFactory $collectionFactory
  32. * @param \Magento\Framework\Registry $coreRegistry
  33. * @param array $data
  34. */
  35. public function __construct(
  36. \Magento\Backend\Block\Template\Context $context,
  37. \Magento\Backend\Helper\Data $backendHelper,
  38. \Magento\Framework\Data\CollectionFactory $collectionFactory,
  39. \Magento\Framework\Registry $coreRegistry,
  40. array $data = []
  41. ) {
  42. $this->_collectionFactory = $collectionFactory;
  43. $this->_coreRegistry = $coreRegistry;
  44. parent::__construct($context, $backendHelper, $data);
  45. }
  46. /**
  47. * Initialize default sorting and html ID
  48. *
  49. * @return void
  50. */
  51. protected function _construct()
  52. {
  53. $this->setId('transactionDetailsGrid');
  54. $this->setPagerVisibility(false);
  55. $this->setFilterVisibility(false);
  56. }
  57. /**
  58. * Prepare collection for grid
  59. *
  60. * @return $this
  61. */
  62. protected function _prepareCollection()
  63. {
  64. $collection = $this->_collectionFactory->create();
  65. foreach ($this->getTransactionAdditionalInfo() as $key => $value) {
  66. $data = new \Magento\Framework\DataObject(['key' => $key, 'value' => $value]);
  67. $collection->addItem($data);
  68. }
  69. $this->setCollection($collection);
  70. return parent::_prepareCollection();
  71. }
  72. /**
  73. * Add columns to grid
  74. *
  75. * @return $this
  76. */
  77. protected function _prepareColumns()
  78. {
  79. $this->addColumn(
  80. 'key',
  81. [
  82. 'header' => __('Key'),
  83. 'index' => 'key',
  84. 'sortable' => false,
  85. 'type' => 'text',
  86. 'header_css_class' => 'col-key',
  87. 'column_css_class' => 'col-key'
  88. ]
  89. );
  90. $this->addColumn(
  91. 'value',
  92. [
  93. 'header' => __('Value'),
  94. 'index' => 'value',
  95. 'sortable' => false,
  96. 'type' => 'text',
  97. 'escape' => true,
  98. 'header_css_class' => 'col-value',
  99. 'column_css_class' => 'col-value'
  100. ]
  101. );
  102. return parent::_prepareColumns();
  103. }
  104. /**
  105. * Retrieve Transaction additional info
  106. *
  107. * @return array
  108. */
  109. public function getTransactionAdditionalInfo()
  110. {
  111. $info = $this->_coreRegistry->registry(
  112. 'current_transaction'
  113. )->getAdditionalInformation(
  114. \Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS
  115. );
  116. return is_array($info) ? $info : [];
  117. }
  118. }