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