Invoice.php 3.7 KB

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