Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Base.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class Base implements AmountInterface
15 {
19  protected $amount;
20 
24  protected $baseAmount;
25 
30 
34  protected $adjustmentAmounts = [];
35 
39  protected $adjustments = [];
40 
45  public function __construct(
46  $amount,
47  array $adjustmentAmounts = []
48  ) {
49  $this->amount = $amount;
50  $this->adjustmentAmounts = $adjustmentAmounts;
51  }
52 
59  public function getValue($exclude = null)
60  {
61  if ($exclude === null) {
62  return $this->amount;
63  } else {
64  if (!is_array($exclude)) {
65  $exclude = [(string)$exclude];
66  }
68  foreach ($exclude as $code) {
69  if ($this->hasAdjustment($code)) {
70  $amount -= $this->adjustmentAmounts[$code];
71  }
72  }
73  return $amount;
74  }
75  }
76 
82  public function __toString()
83  {
84  return (string) $this->getValue();
85  }
86 
92  public function getBaseAmount()
93  {
94  if ($this->baseAmount === null) {
95  $this->calculateAmounts();
96  }
97  return $this->baseAmount;
98  }
99 
106  public function getAdjustmentAmount($adjustmentCode)
107  {
108  return $this->adjustmentAmounts[$adjustmentCode] ?? false;
109  }
110 
116  public function getTotalAdjustmentAmount()
117  {
118  if ($this->totalAdjustmentAmount === null) {
119  $this->calculateAmounts();
120  }
122  }
123 
129  public function getAdjustmentAmounts()
130  {
132  }
133 
140  public function hasAdjustment($adjustmentCode)
141  {
142  return array_key_exists($adjustmentCode, $this->adjustmentAmounts);
143  }
144 
150  protected function calculateAmounts()
151  {
152  $this->baseAmount = $this->amount;
153  $this->totalAdjustmentAmount = 0.;
154  foreach ($this->adjustmentAmounts as $amount) {
155  $this->baseAmount -= $amount;
156  $this->totalAdjustmentAmount += $amount;
157  }
158  }
159 }
if( $block->displayPriceExclTax()||$block->displayBothPrices())(__('Excl. Tax')) ?>"> <?php if ($block -> displayPriceWithWeeeDetails()): ?> <span class="cart-tax-total" data-mage-init=' Magento Weee Helper Data Magento Weee Helper Data title amount
Definition: unit.phtml:68
__construct( $amount, array $adjustmentAmounts=[])
Definition: Base.php:45
getAdjustmentAmount($adjustmentCode)
Definition: Base.php:106
hasAdjustment($adjustmentCode)
Definition: Base.php:140
$code
Definition: info.phtml:12