Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Adjustment.php
Go to the documentation of this file.
1 <?php
8 
12 
18 {
22  protected $taxHelper;
23 
30  public function __construct(
31  Template\Context $context,
33  \Magento\Tax\Helper\Data $helper,
34  array $data = []
35  ) {
36  $this->taxHelper = $helper;
37  parent::__construct($context, $priceCurrency, $data);
38  }
39 
43  protected function apply()
44  {
45  if ($this->displayBothPrices()) {
46  if ($this->getZone() !== \Magento\Framework\Pricing\Render::ZONE_ITEM_OPTION) {
47  $this->amountRender->setPriceDisplayLabel(__('Incl. Tax'));
48  }
49  $this->amountRender->setPriceWrapperCss('price-including-tax');
50  $this->amountRender->setPriceId(
51  $this->buildIdWithPrefix('price-including-tax-')
52  );
53  } elseif ($this->displayPriceExcludingTax()) {
54  $this->amountRender->setDisplayValue(
55  $this->amountRender->getAmount()->getValue($this->getAdjustmentCode())
56  );
57  if ($this->taxHelper->priceIncludesTax() && $this->amountRender->getPriceType() == 'finalPrice') {
58  // for dynamic calculations of prices with any options, use the base price amount
59  $this->amountRender->setPriceType('basePrice');
60  }
61  }
62  return $this->toHtml();
63  }
64 
70  public function getAdjustmentCode()
71  {
72  return \Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE;
73  }
74 
80  public function displayBothPrices()
81  {
82  return $this->taxHelper->displayBothPrices();
83  }
84 
92  public function getDisplayAmountExclTax($exclude = null, $includeContainer = false)
93  {
94  //If exclude is not supplied, use the default
95  if ($exclude === null) {
96  $exclude = $this->getDefaultExclusions();
97  }
98 
99  return $this->formatCurrency(
100  $this->getRawAmount($exclude),
101  $includeContainer
102  );
103  }
104 
111  public function getRawAmount($exclude = null)
112  {
113  //If exclude is not supplied, use the default
114  if ($exclude === null) {
115  $exclude = $this->getDefaultExclusions();
116  }
117 
118  return $this->amountRender->getAmount()->getValue($exclude);
119  }
120 
126  public function getDefaultExclusions()
127  {
128  return [$this->getAdjustmentCode()];
129  }
130 
137  public function getDisplayAmount($includeContainer = true)
138  {
139  return $this->formatCurrency($this->getRawAmount([]), $includeContainer);
140  }
141 
148  public function buildIdWithPrefix($prefix)
149  {
150  $priceId = $this->getPriceId();
151  if (!$priceId) {
152  $priceId = $this->getSaleableItem()->getId();
153  }
154  return $prefix . $priceId . $this->getIdSuffix();
155  }
156 
162  public function displayPriceIncludingTax()
163  {
164  return $this->taxHelper->displayPriceIncludingTax();
165  }
166 
172  public function displayPriceExcludingTax()
173  {
174  return $this->taxHelper->displayPriceExcludingTax();
175  }
176 }
$helper
Definition: iframe.phtml:13
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getDisplayAmount($includeContainer=true)
Definition: Adjustment.php:137
getDisplayAmountExclTax($exclude=null, $includeContainer=false)
Definition: Adjustment.php:92
__()
Definition: __.php:13
__construct(Template\Context $context, PriceCurrencyInterface $priceCurrency, \Magento\Tax\Helper\Data $helper, array $data=[])
Definition: Adjustment.php:30
$prefix
Definition: name.phtml:25
formatCurrency( $amount, $includeContainer=true, $precision=PriceCurrencyInterface::DEFAULT_PRECISION)