public function BulkVariationsCreator::getDuplicationsHtmlList in Commerce Bulk 8
Gets duplicated variations HTML list.
Parameters
array $variations: The commerce product variations.
Return value
array|null An array of used combinations, not used combinations and their number, last variation, variation attributes ids and options, and an HTML list of duplicated variations labels if they are found:
- "last_variation": The variation on the last inline entity form array.
- "used_combinations": The already used combinations.
- "duplicated": The number of duplicated combinations.
- "used": The number of used combinations.
- "duplications_list": HTML list of duplicated combinations if present.
- "attributes": An array with attributes ids and options:
- "ids": The array of field_name => id pairs.
- "options": The array of id => field_label pairs.
- "not_all": The maximum number of combinations to return.
Overrides BulkVariationsCreatorInterface::getDuplicationsHtmlList
1 call to BulkVariationsCreator::getDuplicationsHtmlList()
- BulkVariationsCreator::getNotUsedAttributesCombination in src/
BulkVariationsCreator.php - Gets first not used combination on a product.
File
- src/
BulkVariationsCreator.php, line 352
Class
- BulkVariationsCreator
- Default implementation of the BulkVariationsCreatorInterface.
Namespace
Drupal\commerce_bulkCode
public function getDuplicationsHtmlList(array $variations) {
if (!($all = $this
->getAttributesCombinations($variations))) {
return;
}
if (!empty($all['duplicated'])) {
$all['duplications_list'] = '<ul>';
foreach ($all['duplicated'] as $fields) {
$label = [];
foreach ($fields as $field_name => $id) {
if (isset($all['attributes']['options'][$field_name][$id])) {
$label[] = $all['attributes']['options'][$field_name][$id];
}
}
$label = Html::escape(implode(', ', $label));
$all['duplications_list'] .= '<li>' . $label . '</li>';
}
$all['duplications_list'] .= '</ul>';
$all['duplications_list'] = Markup::create($all['duplications_list']);
}
$all['duplicated'] = count($all['duplicated']);
return $all;
}