Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Detail.php
Go to the documentation of this file.
1 <?php
8 
10 
18 class Detail extends \Magento\Backend\Block\Widget\Container
19 {
25  protected $_txn;
26 
32  protected $_coreRegistry = null;
33 
37  private $adminHelper;
38 
43 
51  public function __construct(
52  \Magento\Backend\Block\Widget\Context $context,
53  \Magento\Framework\Registry $registry,
54  \Magento\Sales\Helper\Admin $adminHelper,
56  array $data = []
57  ) {
58  $this->_coreRegistry = $registry;
59  $this->adminHelper = $adminHelper;
60  $this->orderPaymentRepository = $orderPaymentRepository;
61  parent::__construct($context, $data);
62  }
63 
69  protected function _construct()
70  {
71  parent::_construct();
72 
73  $this->_txn = $this->_coreRegistry->registry('current_transaction');
74  if (!$this->_txn) {
75  return;
76  }
77 
78  $backUrl = $this->_txn->getOrderUrl() ? $this->_txn->getOrderUrl() : $this->getUrl('sales/*/');
79  $this->buttonList->add(
80  'back',
81  ['label' => __('Back'), 'onclick' => "setLocation('{$backUrl}')", 'class' => 'back']
82  );
83 
84  $fetchTransactionAllowed = $this->_authorization->isAllowed('Magento_Sales::transactions_fetch');
85  $canFetchTransaction = $this->orderPaymentRepository->get($this->_txn->getPaymentId())
86  ->getMethodInstance()
87  ->canFetchTransactionInfo();
88 
89  if ($fetchTransactionAllowed && $canFetchTransaction) {
90  $fetchUrl = $this->getUrl('sales/*/fetch', ['_current' => true]);
91  $this->buttonList->add(
92  'fetch',
93  ['label' => __('Fetch'), 'onclick' => "setLocation('{$fetchUrl}')", 'class' => 'button']
94  );
95  }
96  }
97 
103  public function getHeaderText()
104  {
105  return __(
106  "Transaction # %1 | %2",
107  $this->_txn->getTxnId(),
108  $this->formatDate(
109  $this->_txn->getCreatedAt(),
110  \IntlDateFormatter::MEDIUM,
111  true
112  )
113  );
114  }
115 
121  protected function _toHtml()
122  {
123  $this->setTxnIdHtml($this->adminHelper->escapeHtmlWithLinks(
124  $this->_txn->getHtmlTxnId(),
125  ['a']
126  ));
127 
128  $this->setParentTxnIdUrlHtml(
129  $this->escapeHtml($this->getUrl('sales/transactions/view', ['txn_id' => $this->_txn->getParentId()]))
130  );
131 
132  $this->setParentTxnIdHtml($this->escapeHtml($this->_txn->getParentTxnId()));
133 
134  $this->setOrderIncrementIdHtml($this->escapeHtml($this->_txn->getOrder()->getIncrementId()));
135 
136  $this->setTxnTypeHtml($this->escapeHtml(__($this->_txn->getTxnType())));
137 
138  $this->setOrderIdUrlHtml(
139  $this->escapeHtml($this->getUrl('sales/order/view', ['order_id' => $this->_txn->getOrderId()]))
140  );
141 
142  $this->setIsClosedHtml($this->_txn->getIsClosed() ? __('Yes') : __('No'));
143 
144  $createdAt = strtotime(
145  $this->_txn->getCreatedAt()
146  ) ? $this->formatDate(
147  $this->_txn->getCreatedAt(),
148  \IntlDateFormatter::MEDIUM,
149  true
150  ) : __(
151  'N/A'
152  );
153  $this->setCreatedAtHtml($this->escapeHtml($createdAt));
154 
155  return parent::_toHtml();
156  }
157 }
formatDate( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\Framework\Registry $registry, \Magento\Sales\Helper\Admin $adminHelper, OrderPaymentRepositoryInterface $orderPaymentRepository, array $data=[])
Definition: Detail.php:51