Shipment.php 3.8 KB

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