You are here

public function Invoice::getAdjustments in Commerce Invoice 8.2

Gets the adjustments.

Parameters

string[] $adjustment_types: The adjustment types to include. Examples: fee, promotion, tax. Defaults to all adjustment types.

Return value

\Drupal\commerce_order\Adjustment[] The adjustments.

Overrides EntityAdjustableInterface::getAdjustments

1 call to Invoice::getAdjustments()
Invoice::collectAdjustments in src/Entity/Invoice.php
Collects all adjustments that belong to the invoice.

File

src/Entity/Invoice.php, line 299

Class

Invoice
Defines the invoice entity class.

Namespace

Drupal\commerce_invoice\Entity

Code

public function getAdjustments(array $adjustment_types = []) {

  /** @var \Drupal\commerce_order\Adjustment[] $adjustments */
  $adjustments = $this
    ->get('adjustments')
    ->getAdjustments();

  // Filter adjustments by type, if needed.
  if ($adjustment_types) {
    foreach ($adjustments as $index => $adjustment) {
      if (!in_array($adjustment
        ->getType(), $adjustment_types)) {
        unset($adjustments[$index]);
      }
    }
    $adjustments = array_values($adjustments);
  }
  return $adjustments;
}