You are here

public function AttributeValueTop::executeMultiple in Commerce Bulk 8

Executes the plugin for an array of objects.

Parameters

array $objects: An array of entities.

Overrides ActionBase::executeMultiple

File

src/Plugin/Action/AttributeValueTop.php, line 22

Class

AttributeValueTop
Move variations to the top of the list.

Namespace

Drupal\commerce_bulk\Plugin\Action

Code

public function executeMultiple(array $attributes) {
  if (($attribute = reset($attributes)) && ($values = $attribute
    ->getAttribute()
    ->getValues())) {
    $attribute = reset($values);
    unset($values);
    $weight = $attribute
      ->getWeight();
    foreach ($attributes as $attribute) {
      $weight--;
      $attribute
        ->setWeight($weight)
        ->save();
    }
  }
}