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
7 namespace Magento\Tax\Pricing;
8 
11 use Magento\Tax\Helper\Data as TaxHelper;
12 
17 {
21  const ADJUSTMENT_CODE = 'tax';
22 
26  protected $taxHelper;
27 
33  protected $catalogHelper;
34 
38  protected $sortOrder;
39 
45  public function __construct(TaxHelper $taxHelper, \Magento\Catalog\Helper\Data $catalogHelper, $sortOrder = null)
46  {
47  $this->taxHelper = $taxHelper;
48  $this->catalogHelper = $catalogHelper;
49  $this->sortOrder = $sortOrder;
50  }
51 
57  public function getAdjustmentCode()
58  {
59  return self::ADJUSTMENT_CODE;
60  }
61 
67  public function isIncludedInBasePrice()
68  {
69  return $this->taxHelper->priceIncludesTax();
70  }
71 
77  public function isIncludedInDisplayPrice()
78  {
79  return $this->taxHelper->displayPriceIncludingTax() || $this->taxHelper->displayBothPrices();
80  }
81 
90  public function extractAdjustment($amount, SaleableInterface $saleableItem, $context = [])
91  {
92  if ($this->taxHelper->priceIncludesTax()) {
93  $adjustedAmount = $this->catalogHelper->getTaxPrice(
94  $saleableItem,
95  $amount,
96  false,
97  null,
98  null,
99  null,
100  null,
101  null,
102  false
103  );
104  $result = $amount - $adjustedAmount;
105  } else {
106  $result = 0.;
107  }
108  return $result;
109  }
110 
119  public function applyAdjustment($amount, SaleableInterface $saleableItem, $context = [])
120  {
121  return $this->catalogHelper->getTaxPrice(
122  $saleableItem,
123  $amount,
124  true,
125  null,
126  null,
127  null,
128  null,
129  null,
130  false
131  );
132  }
133 
140  public function isExcludedWith($adjustmentCode)
141  {
142  return $this->getAdjustmentCode() === $adjustmentCode;
143  }
144 
150  public function getSortOrder()
151  {
152  return $this->sortOrder;
153  }
154 }
isExcludedWith($adjustmentCode)
Definition: Adjustment.php:140
__construct(TaxHelper $taxHelper, \Magento\Catalog\Helper\Data $catalogHelper, $sortOrder=null)
Definition: Adjustment.php:45
extractAdjustment($amount, SaleableInterface $saleableItem, $context=[])
Definition: Adjustment.php:90
$amount
Definition: order.php:14
applyAdjustment($amount, SaleableInterface $saleableItem, $context=[])
Definition: Adjustment.php:119