Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Adjustment Class Reference
Inheritance diagram for Adjustment:
AdjustmentInterface

Public Member Functions

 __construct (TaxHelper $taxHelper, \Magento\Catalog\Helper\Data $catalogHelper, $sortOrder=null)
 
 getAdjustmentCode ()
 
 isIncludedInBasePrice ()
 
 isIncludedInDisplayPrice ()
 
 extractAdjustment ($amount, SaleableInterface $saleableItem, $context=[])
 
 applyAdjustment ($amount, SaleableInterface $saleableItem, $context=[])
 
 isExcludedWith ($adjustmentCode)
 
 getSortOrder ()
 

Data Fields

const ADJUSTMENT_CODE = 'tax'
 

Protected Attributes

 $taxHelper
 
 $catalogHelper
 
 $sortOrder
 

Detailed Description

Tax pricing adjustment model

Definition at line 16 of file Adjustment.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( TaxHelper  $taxHelper,
\Magento\Catalog\Helper\Data  $catalogHelper,
  $sortOrder = null 
)
Parameters
TaxHelper$taxHelper
\Magento\Catalog\Helper\Data$catalogHelper
int | null$sortOrder

Definition at line 45 of file Adjustment.php.

46  {
47  $this->taxHelper = $taxHelper;
48  $this->catalogHelper = $catalogHelper;
49  $this->sortOrder = $sortOrder;
50  }

Member Function Documentation

◆ applyAdjustment()

applyAdjustment (   $amount,
SaleableInterface  $saleableItem,
  $context = [] 
)

Apply adjustment amount and return result value

Parameters
float$amount
SaleableInterface$saleableItem
null | array$context
Returns
float

Implements AdjustmentInterface.

Definition at line 119 of file Adjustment.php.

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  }
$amount
Definition: order.php:14

◆ extractAdjustment()

extractAdjustment (   $amount,
SaleableInterface  $saleableItem,
  $context = [] 
)

Extract adjustment amount from the given amount value

Parameters
float$amount
SaleableInterface$saleableItem
null | array$context
Returns
float

Implements AdjustmentInterface.

Definition at line 90 of file Adjustment.php.

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  }
$amount
Definition: order.php:14

◆ getAdjustmentCode()

getAdjustmentCode ( )

Get adjustment code

Returns
string

Implements AdjustmentInterface.

Definition at line 57 of file Adjustment.php.

58  {
59  return self::ADJUSTMENT_CODE;
60  }

◆ getSortOrder()

getSortOrder ( )

Return sort order position

Returns
int

Implements AdjustmentInterface.

Definition at line 150 of file Adjustment.php.

151  {
152  return $this->sortOrder;
153  }

◆ isExcludedWith()

isExcludedWith (   $adjustmentCode)

Check if adjustment should be excluded from calculations along with the given adjustment

Parameters
string$adjustmentCode
Returns
bool

Implements AdjustmentInterface.

Definition at line 140 of file Adjustment.php.

141  {
142  return $this->getAdjustmentCode() === $adjustmentCode;
143  }

◆ isIncludedInBasePrice()

isIncludedInBasePrice ( )

Define if adjustment is included in base price

Returns
bool

Implements AdjustmentInterface.

Definition at line 67 of file Adjustment.php.

68  {
69  return $this->taxHelper->priceIncludesTax();
70  }

◆ isIncludedInDisplayPrice()

isIncludedInDisplayPrice ( )

Define if adjustment is included in display price

Returns
bool

Implements AdjustmentInterface.

Definition at line 77 of file Adjustment.php.

78  {
79  return $this->taxHelper->displayPriceIncludingTax() || $this->taxHelper->displayBothPrices();
80  }

Field Documentation

◆ $catalogHelper

$catalogHelper
protected

Definition at line 33 of file Adjustment.php.

◆ $sortOrder

$sortOrder
protected

Definition at line 38 of file Adjustment.php.

◆ $taxHelper

$taxHelper
protected

Definition at line 26 of file Adjustment.php.

◆ ADJUSTMENT_CODE

const ADJUSTMENT_CODE = 'tax'

Adjustment code tax

Definition at line 21 of file Adjustment.php.


The documentation for this class was generated from the following file: