protected function ProductVariationAttributeMapper::getAttributeValues in Commerce Core 8.2
Gets the attribute values of a given set of variations.
Parameters
\Drupal\commerce_product\Entity\ProductVariationInterface[] $variations: The variations.
string $field_name: The field name of the attribute.
callable|null $callback: An optional callback to use for filtering the list.
Return value
array[] The attribute values, keyed by attribute ID.
1 call to ProductVariationAttributeMapper::getAttributeValues()
- ProductVariationAttributeMapper::prepareAttributes in modules/
product/ src/ ProductVariationAttributeMapper.php - Prepares the available attributes for the selected product variation.
File
- modules/
product/ src/ ProductVariationAttributeMapper.php, line 143
Class
Namespace
Drupal\commerce_productCode
protected function getAttributeValues(array $variations, $field_name, callable $callback = NULL) {
$values = [];
foreach ($variations as $variation) {
if (is_null($callback) || call_user_func($callback, $variation)) {
$attribute_value = $variation
->getAttributeValue($field_name);
if ($attribute_value) {
$values[$attribute_value
->id()] = $attribute_value
->label();
}
else {
$values['_none'] = '';
}
}
}
return $values;
}