AbstractOrder.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Order;
  7. use Magento\Sales\Model\Order;
  8. /**
  9. * Adminhtml order abstract block
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class AbstractOrder extends \Magento\Backend\Block\Widget
  16. {
  17. /**
  18. * Core registry
  19. *
  20. * @var \Magento\Framework\Registry
  21. */
  22. protected $_coreRegistry = null;
  23. /**
  24. * Admin helper
  25. *
  26. * @var \Magento\Sales\Helper\Admin
  27. */
  28. protected $_adminHelper;
  29. /**
  30. * @param \Magento\Backend\Block\Template\Context $context
  31. * @param \Magento\Framework\Registry $registry
  32. * @param \Magento\Sales\Helper\Admin $adminHelper
  33. * @param array $data
  34. */
  35. public function __construct(
  36. \Magento\Backend\Block\Template\Context $context,
  37. \Magento\Framework\Registry $registry,
  38. \Magento\Sales\Helper\Admin $adminHelper,
  39. array $data = []
  40. ) {
  41. $this->_adminHelper = $adminHelper;
  42. $this->_coreRegistry = $registry;
  43. parent::__construct($context, $data);
  44. }
  45. /**
  46. * Retrieve available order
  47. *
  48. * @return Order
  49. * @throws \Magento\Framework\Exception\LocalizedException
  50. */
  51. public function getOrder()
  52. {
  53. if ($this->hasOrder()) {
  54. return $this->getData('order');
  55. }
  56. if ($this->_coreRegistry->registry('current_order')) {
  57. return $this->_coreRegistry->registry('current_order');
  58. }
  59. if ($this->_coreRegistry->registry('order')) {
  60. return $this->_coreRegistry->registry('order');
  61. }
  62. throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t get the order instance right now.'));
  63. }
  64. /**
  65. * Get price data object
  66. *
  67. * @return Order|mixed
  68. */
  69. public function getPriceDataObject()
  70. {
  71. $obj = $this->getData('price_data_object');
  72. if ($obj === null) {
  73. return $this->getOrder();
  74. }
  75. return $obj;
  76. }
  77. /**
  78. * Display price attribute
  79. *
  80. * @param string $code
  81. * @param bool $strong
  82. * @param string $separator
  83. * @return string
  84. */
  85. public function displayPriceAttribute($code, $strong = false, $separator = '<br/>')
  86. {
  87. return $this->_adminHelper->displayPriceAttribute($this->getPriceDataObject(), $code, $strong, $separator);
  88. }
  89. /**
  90. * Display prices
  91. *
  92. * @param float $basePrice
  93. * @param float $price
  94. * @param bool $strong
  95. * @param string $separator
  96. * @return string
  97. */
  98. public function displayPrices($basePrice, $price, $strong = false, $separator = '<br/>')
  99. {
  100. return $this->_adminHelper->displayPrices(
  101. $this->getPriceDataObject(),
  102. $basePrice,
  103. $price,
  104. $strong,
  105. $separator
  106. );
  107. }
  108. /**
  109. * Retrieve order totals block settings
  110. *
  111. * @return array
  112. */
  113. public function getOrderTotalData()
  114. {
  115. return [];
  116. }
  117. /**
  118. * Retrieve order info block settings
  119. *
  120. * @return array
  121. */
  122. public function getOrderInfoData()
  123. {
  124. return [];
  125. }
  126. /**
  127. * Retrieve subtotal price include tax html formatted content
  128. *
  129. * @param \Magento\Framework\DataObject $order
  130. * @return string
  131. */
  132. public function displayShippingPriceInclTax($order)
  133. {
  134. $shipping = $order->getShippingInclTax();
  135. if ($shipping) {
  136. $baseShipping = $order->getBaseShippingInclTax();
  137. } else {
  138. $shipping = $order->getShippingAmount() + $order->getShippingTaxAmount();
  139. $baseShipping = $order->getBaseShippingAmount() + $order->getBaseShippingTaxAmount();
  140. }
  141. return $this->displayPrices($baseShipping, $shipping, false, ' ');
  142. }
  143. }