You are here

public function ProductAttribute::getValues in Commerce Core 8.2

Gets the attribute values.

Return value

\Drupal\commerce_product\Entity\ProductAttributeValueInterface[] The attribute values.

Overrides ProductAttributeInterface::getValues

File

modules/product/src/Entity/ProductAttribute.php, line 84

Class

ProductAttribute
Defines the product attribute entity class.

Namespace

Drupal\commerce_product\Entity

Code

public function getValues() {

  /** @var \Drupal\commerce_product\ProductAttributeValueStorageInterface $storage */
  $storage = $this
    ->entityTypeManager()
    ->getStorage('commerce_product_attribute_value');
  $values = $storage
    ->loadMultipleByAttribute($this
    ->id());

  // Make sure that the values are returned in the attribute language.
  $langcode = $this
    ->language()
    ->getId();
  foreach ($values as $index => $value) {
    if ($value
      ->hasTranslation($langcode)) {
      $values[$index] = $value
        ->getTranslation($langcode);
    }
  }
  return $values;
}