You are here

public function ProductVariationAttributeMapperInterface::selectVariation in Commerce Core 8.2

Selects the best matching variation for the given attribute values.

Takes the first variation that matches the most attribute values. Partial matches are considered when a full match cannot be made. For example, when given [Red, Small, Cotton], the search priority is: 1) [Red, Small, Cotton] 2) [Red, Small] 3) [Red]

Parameters

\Drupal\commerce_product\Entity\ProductVariationInterface[] $variations: The variations.

array $attribute_values: Attribute value IDs, keyed by the field name.

Return value

\Drupal\commerce_product\Entity\ProductVariationInterface|null The selected variation, or NULL if none could be selected.

1 method overrides ProductVariationAttributeMapperInterface::selectVariation()
ProductVariationAttributeMapper::selectVariation in modules/product/src/ProductVariationAttributeMapper.php
Selects the best matching variation for the given attribute values.

File

modules/product/src/ProductVariationAttributeMapperInterface.php, line 32

Class

ProductVariationAttributeMapperInterface
Provides logic for selecting variations using attributes.

Namespace

Drupal\commerce_product

Code

public function selectVariation(array $variations, array $attribute_values = []);