History.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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\View;
  7. /**
  8. * Order history block
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class History extends \Magento\Backend\Block\Template
  14. {
  15. /**
  16. * Core registry
  17. *
  18. * @var \Magento\Framework\Registry
  19. */
  20. protected $_coreRegistry = null;
  21. /**
  22. * Sales data
  23. *
  24. * @var \Magento\Sales\Helper\Data
  25. */
  26. protected $_salesData = null;
  27. /**
  28. * @var \Magento\Sales\Helper\Admin
  29. */
  30. private $adminHelper;
  31. /**
  32. * @param \Magento\Backend\Block\Template\Context $context
  33. * @param \Magento\Sales\Helper\Data $salesData
  34. * @param \Magento\Framework\Registry $registry
  35. * @param \Magento\Sales\Helper\Admin $adminHelper
  36. * @param array $data
  37. */
  38. public function __construct(
  39. \Magento\Backend\Block\Template\Context $context,
  40. \Magento\Sales\Helper\Data $salesData,
  41. \Magento\Framework\Registry $registry,
  42. \Magento\Sales\Helper\Admin $adminHelper,
  43. array $data = []
  44. ) {
  45. $this->_coreRegistry = $registry;
  46. $this->_salesData = $salesData;
  47. parent::__construct($context, $data);
  48. $this->adminHelper = $adminHelper;
  49. }
  50. /**
  51. * Preparing global layout
  52. *
  53. * @return $this
  54. */
  55. protected function _prepareLayout()
  56. {
  57. $onclick = "submitAndReloadArea($('order_history_block').parentNode, '" . $this->getSubmitUrl() . "')";
  58. $button = $this->getLayout()->createBlock(
  59. \Magento\Backend\Block\Widget\Button::class
  60. )->setData(
  61. ['label' => __('Submit Comment'), 'class' => 'action-save action-secondary', 'onclick' => $onclick]
  62. );
  63. $this->setChild('submit_button', $button);
  64. return parent::_prepareLayout();
  65. }
  66. /**
  67. * Get stat uses
  68. *
  69. * @return array
  70. */
  71. public function getStatuses()
  72. {
  73. $state = $this->getOrder()->getState();
  74. $statuses = $this->getOrder()->getConfig()->getStateStatuses($state);
  75. return $statuses;
  76. }
  77. /**
  78. * Check allow to send order comment email
  79. *
  80. * @return bool
  81. */
  82. public function canSendCommentEmail()
  83. {
  84. return $this->_salesData->canSendOrderCommentEmail($this->getOrder()->getStore()->getId())
  85. && $this->_authorization->isAllowed('Magento_Sales::email');
  86. }
  87. /**
  88. * Retrieve order model
  89. *
  90. * @return \Magento\Sales\Model\Order
  91. */
  92. public function getOrder()
  93. {
  94. return $this->_coreRegistry->registry('sales_order');
  95. }
  96. /**
  97. * Check allow to add comment
  98. *
  99. * @return bool
  100. */
  101. public function canAddComment()
  102. {
  103. return $this->_authorization->isAllowed('Magento_Sales::comment') && $this->getOrder()->canComment();
  104. }
  105. /**
  106. * Submit URL getter
  107. *
  108. * @return string
  109. */
  110. public function getSubmitUrl()
  111. {
  112. return $this->getUrl('sales/*/addComment', ['order_id' => $this->getOrder()->getId()]);
  113. }
  114. /**
  115. * Customer Notification Applicable check method
  116. *
  117. * @param \Magento\Sales\Model\Order\Status\History $history
  118. * @return bool
  119. */
  120. public function isCustomerNotificationNotApplicable(\Magento\Sales\Model\Order\Status\History $history)
  121. {
  122. return $history->isCustomerNotificationNotApplicable();
  123. }
  124. /**
  125. * Replace links in string
  126. *
  127. * @param array|string $data
  128. * @param null|array $allowedTags
  129. * @return string
  130. */
  131. public function escapeHtml($data, $allowedTags = null)
  132. {
  133. return $this->adminHelper->escapeHtmlWithLinks($data, $allowedTags);
  134. }
  135. }