You are here

public function Order::getAdjustments in Commerce Core 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

2 calls to Order::getAdjustments()
Order::clearAdjustments in modules/order/src/Entity/Order.php
Removes all adjustments that belong to the order.
Order::collectAdjustments in modules/order/src/Entity/Order.php
Collects all adjustments that belong to the order.

File

modules/order/src/Entity/Order.php, line 330

Class

Order
Defines the order entity class.

Namespace

Drupal\commerce_order\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;
}