Creditmemo.php 3.7 KB

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