View.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Order;
  7. use Magento\Customer\Model\Context;
  8. /**
  9. * Sales order view block
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class View extends \Magento\Framework\View\Element\Template
  15. {
  16. /**
  17. * @var string
  18. */
  19. protected $_template = 'Magento_Sales::order/view.phtml';
  20. /**
  21. * Core registry
  22. *
  23. * @var \Magento\Framework\Registry
  24. */
  25. protected $_coreRegistry = null;
  26. /**
  27. * @var \Magento\Framework\App\Http\Context
  28. * @since 101.0.0
  29. */
  30. protected $httpContext;
  31. /**
  32. * @var \Magento\Payment\Helper\Data
  33. */
  34. protected $_paymentHelper;
  35. /**
  36. * @param \Magento\Framework\View\Element\Template\Context $context
  37. * @param \Magento\Framework\Registry $registry
  38. * @param \Magento\Framework\App\Http\Context $httpContext
  39. * @param \Magento\Payment\Helper\Data $paymentHelper
  40. * @param array $data
  41. */
  42. public function __construct(
  43. \Magento\Framework\View\Element\Template\Context $context,
  44. \Magento\Framework\Registry $registry,
  45. \Magento\Framework\App\Http\Context $httpContext,
  46. \Magento\Payment\Helper\Data $paymentHelper,
  47. array $data = []
  48. ) {
  49. $this->_paymentHelper = $paymentHelper;
  50. $this->_coreRegistry = $registry;
  51. $this->httpContext = $httpContext;
  52. parent::__construct($context, $data);
  53. $this->_isScopePrivate = true;
  54. }
  55. /**
  56. * @return void
  57. */
  58. protected function _prepareLayout()
  59. {
  60. $this->pageConfig->getTitle()->set(__('Order # %1', $this->getOrder()->getRealOrderId()));
  61. $infoBlock = $this->_paymentHelper->getInfoBlock($this->getOrder()->getPayment(), $this->getLayout());
  62. $this->setChild('payment_info', $infoBlock);
  63. }
  64. /**
  65. * @return string
  66. */
  67. public function getPaymentInfoHtml()
  68. {
  69. return $this->getChildHtml('payment_info');
  70. }
  71. /**
  72. * Retrieve current order model instance
  73. *
  74. * @return \Magento\Sales\Model\Order
  75. */
  76. public function getOrder()
  77. {
  78. return $this->_coreRegistry->registry('current_order');
  79. }
  80. /**
  81. * Return back url for logged in and guest users
  82. *
  83. * @return string
  84. */
  85. public function getBackUrl()
  86. {
  87. if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
  88. return $this->getUrl('*/*/history');
  89. }
  90. return $this->getUrl('*/*/form');
  91. }
  92. /**
  93. * Return back title for logged in and guest users
  94. *
  95. * @return \Magento\Framework\Phrase
  96. */
  97. public function getBackTitle()
  98. {
  99. if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
  100. return __('Back to My Orders');
  101. }
  102. return __('View Another Order');
  103. }
  104. /**
  105. * @param object $order
  106. * @return string
  107. */
  108. public function getInvoiceUrl($order)
  109. {
  110. return $this->getUrl('*/*/invoice', ['order_id' => $order->getId()]);
  111. }
  112. /**
  113. * @param object $order
  114. * @return string
  115. */
  116. public function getShipmentUrl($order)
  117. {
  118. return $this->getUrl('*/*/shipment', ['order_id' => $order->getId()]);
  119. }
  120. /**
  121. * @param object $order
  122. * @return string
  123. */
  124. public function getCreditmemoUrl($order)
  125. {
  126. return $this->getUrl('*/*/creditmemo', ['order_id' => $order->getId()]);
  127. }
  128. }