You are here

public function Promotion::setConditions in Commerce Core 8.2

Sets the conditions.

Parameters

\Drupal\commerce\Plugin\Commerce\Condition\ConditionInterface[] $conditions: The conditions.

Return value

$this

Overrides PromotionInterface::setConditions

File

modules/promotion/src/Entity/Promotion.php, line 287

Class

Promotion
Defines the promotion entity class.

Namespace

Drupal\commerce_promotion\Entity

Code

public function setConditions(array $conditions) {
  $this
    ->set('conditions', []);
  foreach ($conditions as $condition) {
    if ($condition instanceof ConditionInterface) {
      $this
        ->get('conditions')
        ->appendItem([
        'target_plugin_id' => $condition
          ->getPluginId(),
        'target_plugin_configuration' => $condition
          ->getConfiguration(),
      ]);
    }
  }
  return $this;
}