You are here

public function ChainPriceResolver::resolve in Commerce Core 8.2

Resolves a price for the given purchasable entity.

Use $context->getData('field_name', 'price') to get the name of the field for which the price is being resolved (e.g "list_price", "price").

Parameters

\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.

string $quantity: The quantity.

\Drupal\commerce\Context $context: The context.

Return value

\Drupal\commerce_price\Price|null A price value object, if resolved. Otherwise NULL, indicating that the next resolver in the chain should be called.

Overrides PriceResolverInterface::resolve

File

modules/price/src/Resolver/ChainPriceResolver.php, line 47

Class

ChainPriceResolver
Default implementation of the chain base price resolver.

Namespace

Drupal\commerce_price\Resolver

Code

public function resolve(PurchasableEntityInterface $entity, $quantity, Context $context) {
  foreach ($this->resolvers as $resolver) {
    $result = $resolver
      ->resolve($entity, $quantity, $context);
    if ($result) {
      return $result;
    }
  }
}