Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Total.php
Go to the documentation of this file.
1 <?php
7 
15 {
19  protected $totalAmounts = [];
20 
24  protected $baseTotalAmounts = [];
25 
31  private $serializer;
32 
39  public function __construct(
40  array $data = [],
41  \Magento\Framework\Serialize\Serializer\Json $serializer = null
42  ) {
43  $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
44  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
45  parent::__construct($data);
46  }
47 
55  public function setTotalAmount($code, $amount)
56  {
57  $this->totalAmounts[$code] = $amount;
58  if ($code != 'subtotal') {
59  $code = $code . '_amount';
60  }
61  $this->setData($code, $amount);
62 
63  return $this;
64  }
65 
73  public function setBaseTotalAmount($code, $amount)
74  {
75  $this->baseTotalAmounts[$code] = $amount;
76  if ($code != 'subtotal') {
77  $code = $code . '_amount';
78  }
79  $this->setData('base_' . $code, $amount);
80 
81  return $this;
82  }
83 
91  public function addTotalAmount($code, $amount)
92  {
93  $amount = $this->getTotalAmount($code) + $amount;
94  $this->setTotalAmount($code, $amount);
95 
96  return $this;
97  }
98 
106  public function addBaseTotalAmount($code, $amount)
107  {
110 
111  return $this;
112  }
113 
120  public function getTotalAmount($code)
121  {
122  if (isset($this->totalAmounts[$code])) {
123  return $this->totalAmounts[$code];
124  }
125 
126  return 0;
127  }
128 
135  public function getBaseTotalAmount($code)
136  {
137  if (isset($this->baseTotalAmounts[$code])) {
138  return $this->baseTotalAmounts[$code];
139  }
140 
141  return 0;
142  }
143 
144  //@codeCoverageIgnoreStart
145 
151  public function getAllTotalAmounts()
152  {
153  return $this->totalAmounts;
154  }
155 
161  public function getAllBaseTotalAmounts()
162  {
164  }
165 
166  //@codeCoverageIgnoreEnd
167 
176  public function setFullInfo($info)
177  {
178  $this->setData('full_info', $info);
179  return $this;
180  }
181 
188  public function getFullInfo()
189  {
190  $fullInfo = $this->getData('full_info');
191  if (is_string($fullInfo)) {
192  $fullInfo = $this->serializer->unserialize($fullInfo);
193  }
194  return $fullInfo;
195  }
196 }
getData($key='', $index=null)
Definition: DataObject.php:119
$amount
Definition: order.php:14
__construct(array $data=[], \Magento\Framework\Serialize\Serializer\Json $serializer=null)
Definition: Total.php:39
setData($key, $value=null)
Definition: DataObject.php:72
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
$code
Definition: info.phtml:12