You are here

public function ProductVariation::getAttributeValue in Commerce Core 8.2

Gets the attribute value for the given field name.

Parameters

string $field_name: The field name.

Return value

\Drupal\commerce_product\Entity\ProductAttributeValueInterface|null The attribute value, or NULL.

Overrides ProductVariationInterface::getAttributeValue

File

modules/product/src/Entity/ProductVariation.php, line 339

Class

ProductVariation
Defines the product variation entity class.

Namespace

Drupal\commerce_product\Entity

Code

public function getAttributeValue($field_name) {
  $attribute_field_names = $this
    ->getAttributeFieldNames();
  if (!in_array($field_name, $attribute_field_names)) {
    throw new \InvalidArgumentException(sprintf('Unknown attribute field name "%s".', $field_name));
  }
  $attribute_value = $this
    ->getTranslatedReferencedEntity($field_name);
  return $attribute_value;
}