Success.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Block\Onepage;
  7. use Magento\Customer\Model\Context;
  8. use Magento\Sales\Model\Order;
  9. /**
  10. * One page checkout success page
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class Success extends \Magento\Framework\View\Element\Template
  16. {
  17. /**
  18. * @var \Magento\Checkout\Model\Session
  19. */
  20. protected $_checkoutSession;
  21. /**
  22. * @var \Magento\Sales\Model\Order\Config
  23. */
  24. protected $_orderConfig;
  25. /**
  26. * @var \Magento\Framework\App\Http\Context
  27. */
  28. protected $httpContext;
  29. /**
  30. * @param \Magento\Framework\View\Element\Template\Context $context
  31. * @param \Magento\Checkout\Model\Session $checkoutSession
  32. * @param \Magento\Sales\Model\Order\Config $orderConfig
  33. * @param \Magento\Framework\App\Http\Context $httpContext
  34. * @param array $data
  35. */
  36. public function __construct(
  37. \Magento\Framework\View\Element\Template\Context $context,
  38. \Magento\Checkout\Model\Session $checkoutSession,
  39. \Magento\Sales\Model\Order\Config $orderConfig,
  40. \Magento\Framework\App\Http\Context $httpContext,
  41. array $data = []
  42. ) {
  43. parent::__construct($context, $data);
  44. $this->_checkoutSession = $checkoutSession;
  45. $this->_orderConfig = $orderConfig;
  46. $this->_isScopePrivate = true;
  47. $this->httpContext = $httpContext;
  48. }
  49. /**
  50. * Render additional order information lines and return result html
  51. *
  52. * @return string
  53. */
  54. public function getAdditionalInfoHtml()
  55. {
  56. return $this->_layout->renderElement('order.success.additional.info');
  57. }
  58. /**
  59. * Initialize data and prepare it for output
  60. *
  61. * @return string
  62. */
  63. protected function _beforeToHtml()
  64. {
  65. $this->prepareBlockData();
  66. return parent::_beforeToHtml();
  67. }
  68. /**
  69. * Prepares block data
  70. *
  71. * @return void
  72. */
  73. protected function prepareBlockData()
  74. {
  75. $order = $this->_checkoutSession->getLastRealOrder();
  76. $this->addData(
  77. [
  78. 'is_order_visible' => $this->isVisible($order),
  79. 'view_order_url' => $this->getUrl(
  80. 'sales/order/view/',
  81. ['order_id' => $order->getEntityId()]
  82. ),
  83. 'print_url' => $this->getUrl(
  84. 'sales/order/print',
  85. ['order_id' => $order->getEntityId()]
  86. ),
  87. 'can_print_order' => $this->isVisible($order),
  88. 'can_view_order' => $this->canViewOrder($order),
  89. 'order_id' => $order->getIncrementId()
  90. ]
  91. );
  92. }
  93. /**
  94. * Is order visible
  95. *
  96. * @param Order $order
  97. * @return bool
  98. */
  99. protected function isVisible(Order $order)
  100. {
  101. return !in_array(
  102. $order->getStatus(),
  103. $this->_orderConfig->getInvisibleOnFrontStatuses()
  104. );
  105. }
  106. /**
  107. * Can view order
  108. *
  109. * @param Order $order
  110. * @return bool
  111. */
  112. protected function canViewOrder(Order $order)
  113. {
  114. return $this->httpContext->getValue(Context::CONTEXT_AUTH)
  115. && $this->isVisible($order);
  116. }
  117. /**
  118. * @return string
  119. * @since 100.2.0
  120. */
  121. public function getContinueUrl()
  122. {
  123. return $this->_storeManager->getStore()->getBaseUrl();
  124. }
  125. }