You are here

public function ProductVariation::getAttributeValueId in Commerce Core 8.2

Gets the attribute value id for the given field name.

Parameters

string $field_name: The field name.

Return value

int|null The attribute value ID, or NULL.

Overrides ProductVariationInterface::getAttributeValueId

File

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

Class

ProductVariation
Defines the product variation entity class.

Namespace

Drupal\commerce_product\Entity

Code

public function getAttributeValueId($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_id = NULL;
  $field = $this
    ->get($field_name);
  if (!$field
    ->isEmpty()) {
    $attribute_id = $field->target_id;
  }
  return $attribute_id;
}