You are here

class ChainPriceResolver in Price 2.0.x

Default implementation of the chain base price resolver.

Hierarchy

Expanded class hierarchy of ChainPriceResolver

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

File

src/Resolver/ChainPriceResolver.php, line 11

Namespace

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

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

  /**
   * Constructs a new ChainBasePriceResolver object.
   *
   * @param \Drupal\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(ContentEntityInterface $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.