You are here

public function OrderItem::addAdjustment in Commerce Core 8.2

Adds an adjustment.

Parameters

\Drupal\commerce_order\Adjustment $adjustment: The adjustment.

Return value

$this

Overrides EntityAdjustableInterface::addAdjustment

File

modules/order/src/Entity/OrderItem.php, line 184

Class

OrderItem
Defines the order item entity class.

Namespace

Drupal\commerce_order\Entity

Code

public function addAdjustment(Adjustment $adjustment) {
  $this
    ->get('adjustments')
    ->appendItem($adjustment);
  if ($this
    ->getOrder()) {
    $this
      ->getOrder()
      ->recalculateTotalPrice();
  }
  return $this;
}