Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxAdjustment.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Weee\Pricing;
8 
13 use Magento\Weee\Helper\Data as WeeeHelper;
14 use Magento\Tax\Helper\Data as TaxHelper;
15 
20 {
24  const ADJUSTMENT_CODE = 'weee_tax';
25 
31  protected $weeeHelper;
32 
36  protected $taxHelper;
37 
43  protected $sortOrder;
44 
48  protected $priceCurrency;
49 
58  public function __construct(
59  WeeeHelper $weeeHelper,
60  TaxHelper $taxHelper,
62  $sortOrder = null
63  ) {
64  $this->weeeHelper = $weeeHelper;
65  $this->taxHelper = $taxHelper;
66  $this->priceCurrency = $priceCurrency;
67  $this->sortOrder = $sortOrder;
68  }
69 
75  public function getAdjustmentCode()
76  {
77  return self::ADJUSTMENT_CODE;
78  }
79 
86  public function isIncludedInBasePrice()
87  {
88  return false;
89  }
90 
96  public function isIncludedInDisplayPrice()
97  {
98  if ($this->taxHelper->displayPriceExcludingTax()) {
99  return false;
100  }
101  if ($this->weeeHelper->isEnabled() == true &&
102  $this->weeeHelper->isTaxable() == true &&
103  $this->weeeHelper->typeOfDisplay([\Magento\Weee\Model\Tax::DISPLAY_EXCL]) == false) {
104  return true;
105  } else {
106  return false;
107  }
108  }
109 
119  public function extractAdjustment($amount, SaleableInterface $saleableItem, $context = [])
120  {
121  return 0;
122  }
123 
132  public function applyAdjustment($amount, SaleableInterface $saleableItem, $context = [])
133  {
135  return $amount;
136  }
137  return $amount + $this->getAmount($saleableItem);
138  }
139 
146  public function isExcludedWith($adjustmentCode)
147  {
148  return (($adjustmentCode == self::ADJUSTMENT_CODE) ||
149  ($adjustmentCode == \Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE));
150  }
151 
158  protected function getAmount(SaleableInterface $saleableItem)
159  {
160  $weeeTaxAmount = 0;
161  $attributes = $this->weeeHelper->getProductWeeeAttributes($saleableItem, null, null, null, true, false);
162  if ($attributes != null) {
163  foreach ($attributes as $attribute) {
164  $weeeTaxAmount += $attribute->getData('tax_amount');
165  }
166  }
167  $weeeTaxAmount = $this->priceCurrency->convert($weeeTaxAmount);
168  return $weeeTaxAmount;
169  }
170 
176  public function getSortOrder()
177  {
178  return $this->sortOrder;
179  }
180 }
__construct(WeeeHelper $weeeHelper, TaxHelper $taxHelper, PriceCurrencyInterface $priceCurrency, $sortOrder=null)
applyAdjustment($amount, SaleableInterface $saleableItem, $context=[])
getAmount(SaleableInterface $saleableItem)
$amount
Definition: order.php:14
$attributes
Definition: matrix.phtml:13
extractAdjustment($amount, SaleableInterface $saleableItem, $context=[])