Totals.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml;
  7. class Totals extends \Magento\Sales\Block\Order\Totals
  8. {
  9. /**
  10. * Admin helper
  11. *
  12. * @var \Magento\Sales\Helper\Admin
  13. */
  14. protected $_adminHelper;
  15. /**
  16. * @param \Magento\Framework\View\Element\Template\Context $context
  17. * @param \Magento\Framework\Registry $registry
  18. * @param \Magento\Sales\Helper\Admin $adminHelper
  19. * @param array $data
  20. */
  21. public function __construct(
  22. \Magento\Framework\View\Element\Template\Context $context,
  23. \Magento\Framework\Registry $registry,
  24. \Magento\Sales\Helper\Admin $adminHelper,
  25. array $data = []
  26. ) {
  27. $this->_adminHelper = $adminHelper;
  28. parent::__construct($context, $registry, $data);
  29. }
  30. /**
  31. * Format total value based on order currency
  32. *
  33. * @param \Magento\Framework\DataObject $total
  34. * @return string
  35. */
  36. public function formatValue($total)
  37. {
  38. if (!$total->getIsFormated()) {
  39. return $this->_adminHelper->displayPrices($this->getOrder(), $total->getBaseValue(), $total->getValue());
  40. }
  41. return $total->getValue();
  42. }
  43. /**
  44. * Initialize order totals array
  45. *
  46. * @return $this
  47. */
  48. protected function _initTotals()
  49. {
  50. $this->_totals = [];
  51. $this->_totals['subtotal'] = new \Magento\Framework\DataObject(
  52. [
  53. 'code' => 'subtotal',
  54. 'value' => $this->getSource()->getSubtotal(),
  55. 'base_value' => $this->getSource()->getBaseSubtotal(),
  56. 'label' => __('Subtotal'),
  57. ]
  58. );
  59. /**
  60. * Add shipping
  61. */
  62. if (!$this->getSource()->getIsVirtual() && ((double)$this->getSource()->getShippingAmount() ||
  63. $this->getSource()->getShippingDescription())
  64. ) {
  65. $this->_totals['shipping'] = new \Magento\Framework\DataObject(
  66. [
  67. 'code' => 'shipping',
  68. 'value' => $this->getSource()->getShippingAmount(),
  69. 'base_value' => $this->getSource()->getBaseShippingAmount(),
  70. 'label' => __('Shipping & Handling'),
  71. ]
  72. );
  73. }
  74. /**
  75. * Add discount
  76. */
  77. if ((double)$this->getSource()->getDiscountAmount() != 0) {
  78. if ($this->getSource()->getDiscountDescription()) {
  79. $discountLabel = __('Discount (%1)', $this->getSource()->getDiscountDescription());
  80. } else {
  81. $discountLabel = __('Discount');
  82. }
  83. $this->_totals['discount'] = new \Magento\Framework\DataObject(
  84. [
  85. 'code' => 'discount',
  86. 'value' => $this->getSource()->getDiscountAmount(),
  87. 'base_value' => $this->getSource()->getBaseDiscountAmount(),
  88. 'label' => $discountLabel,
  89. ]
  90. );
  91. }
  92. $this->_totals['grand_total'] = new \Magento\Framework\DataObject(
  93. [
  94. 'code' => 'grand_total',
  95. 'strong' => true,
  96. 'value' => $this->getSource()->getGrandTotal(),
  97. 'base_value' => $this->getSource()->getBaseGrandTotal(),
  98. 'label' => __('Grand Total'),
  99. 'area' => 'footer',
  100. ]
  101. );
  102. return $this;
  103. }
  104. }