You are here

class ChainPriceResolver in Commerce Core 8.2

Default implementation of the chain base price resolver.

Hierarchy

Expanded class hierarchy of ChainPriceResolver

1 string reference to 'ChainPriceResolver'
commerce_price.services.yml in modules/price/commerce_price.services.yml
modules/price/commerce_price.services.yml
1 service uses ChainPriceResolver
commerce_price.chain_price_resolver in modules/price/commerce_price.services.yml
Drupal\commerce_price\Resolver\ChainPriceResolver

File

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

Namespace

Drupal\commerce_price\Resolver
View source
class ChainPriceResolver implements ChainPriceResolverInterface {

  /**
   * The resolvers.
   *
   * @var \Drupal\commerce_price\Resolver\PriceResolverInterface[]
   */
  protected $resolvers = [];

  /**
   * Constructs a new ChainBasePriceResolver object.
   *
   * @param \Drupal\commerce_price\Resolver\PriceResolverInterface[] $resolvers
   *   The resolvers.
   */
  public function __construct(array $resolvers = []) {
    $this->resolvers = $resolvers;
  }

  /**
   * {@inheritdoc}
   */
  public function addResolver(PriceResolverInterface $resolver) {
    $this->resolvers[] = $resolver;
  }

  /**
   * {@inheritdoc}
   */
  public function getResolvers() {
    return $this->resolvers;
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
ChainPriceResolver::$resolvers protected property The resolvers.
ChainPriceResolver::addResolver public function Adds a resolver. Overrides ChainPriceResolverInterface::addResolver
ChainPriceResolver::getResolvers public function Gets all added resolvers. Overrides ChainPriceResolverInterface::getResolvers
ChainPriceResolver::resolve public function Resolves a price for the given purchasable entity. Overrides PriceResolverInterface::resolve
ChainPriceResolver::__construct public function Constructs a new ChainBasePriceResolver object.