Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Totals.php
Go to the documentation of this file.
1 <?php
7 
9 {
15  protected $_adminHelper;
16 
23  public function __construct(
24  \Magento\Framework\View\Element\Template\Context $context,
25  \Magento\Framework\Registry $registry,
26  \Magento\Sales\Helper\Admin $adminHelper,
27  array $data = []
28  ) {
29  $this->_adminHelper = $adminHelper;
30  parent::__construct($context, $registry, $data);
31  }
32 
39  public function formatValue($total)
40  {
41  if (!$total->getIsFormated()) {
42  return $this->_adminHelper->displayPrices($this->getOrder(), $total->getBaseValue(), $total->getValue());
43  }
44  return $total->getValue();
45  }
46 
52  protected function _initTotals()
53  {
54  $this->_totals = [];
55  $this->_totals['subtotal'] = new \Magento\Framework\DataObject(
56  [
57  'code' => 'subtotal',
58  'value' => $this->getSource()->getSubtotal(),
59  'base_value' => $this->getSource()->getBaseSubtotal(),
60  'label' => __('Subtotal'),
61  ]
62  );
63 
67  if (!$this->getSource()->getIsVirtual() && ((double)$this->getSource()->getShippingAmount() ||
68  $this->getSource()->getShippingDescription())
69  ) {
70  $this->_totals['shipping'] = new \Magento\Framework\DataObject(
71  [
72  'code' => 'shipping',
73  'value' => $this->getSource()->getShippingAmount(),
74  'base_value' => $this->getSource()->getBaseShippingAmount(),
75  'label' => __('Shipping & Handling'),
76  ]
77  );
78  }
79 
83  if ((double)$this->getSource()->getDiscountAmount() != 0) {
84  if ($this->getSource()->getDiscountDescription()) {
85  $discountLabel = __('Discount (%1)', $this->getSource()->getDiscountDescription());
86  } else {
87  $discountLabel = __('Discount');
88  }
89  $this->_totals['discount'] = new \Magento\Framework\DataObject(
90  [
91  'code' => 'discount',
92  'value' => $this->getSource()->getDiscountAmount(),
93  'base_value' => $this->getSource()->getBaseDiscountAmount(),
94  'label' => $discountLabel,
95  ]
96  );
97  }
98 
99  $this->_totals['grand_total'] = new \Magento\Framework\DataObject(
100  [
101  'code' => 'grand_total',
102  'strong' => true,
103  'value' => $this->getSource()->getGrandTotal(),
104  'base_value' => $this->getSource()->getBaseGrandTotal(),
105  'label' => __('Grand Total'),
106  'area' => 'footer',
107  ]
108  );
109 
110  return $this;
111  }
112 }
__()
Definition: __.php:13
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Sales\Helper\Admin $adminHelper, array $data=[])
Definition: Totals.php:23