public function VariationTop::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/ VariationTop.php, line 22
Class
- VariationTop
- Move variations to the top of the list.
Namespace
Drupal\commerce_bulk\Plugin\ActionCode
public function executeMultiple(array $variations) {
if ($count = count($variations)) {
$variation = reset($variations);
$product = $variation
->getProduct();
$all_variations = $product
->getVariations();
foreach ($all_variations as $index => $variation) {
if (in_array($variation, $variations)) {
unset($all_variations[$index]);
$count--;
if (!$count) {
break;
}
}
}
$all_variations = array_values(array_merge($variations, $all_variations));
$product
->setVariations($all_variations);
$product
->save();
}
}