You are here

class ChainTaxRateResolver in Commerce Core 8.2

Hierarchy

Expanded class hierarchy of ChainTaxRateResolver

1 string reference to 'ChainTaxRateResolver'
commerce_tax.services.yml in modules/tax/commerce_tax.services.yml
modules/tax/commerce_tax.services.yml
1 service uses ChainTaxRateResolver
commerce_tax.chain_tax_rate_resolver in modules/tax/commerce_tax.services.yml
Drupal\commerce_tax\Resolver\ChainTaxRateResolver

File

modules/tax/src/Resolver/ChainTaxRateResolver.php, line 9

Namespace

Drupal\commerce_tax\Resolver
View source
class ChainTaxRateResolver implements ChainTaxRateResolverInterface {
  use TaxTypeAwareTrait;

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

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

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

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

  /**
   * {@inheritdoc}
   */
  public function resolve(TaxZone $zone, OrderItemInterface $order_item, ProfileInterface $customer_profile) {
    $result = NULL;
    foreach ($this->resolvers as $resolver) {
      if ($resolver instanceof TaxTypeAwareInterface) {
        $resolver
          ->setTaxType($this->taxType);
      }
      $result = $resolver
        ->resolve($zone, $order_item, $customer_profile);
      if ($result) {
        break;
      }
    }
    return $result;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ChainTaxRateResolver::$resolvers protected property The resolvers.
ChainTaxRateResolver::addResolver public function Adds a resolver. Overrides ChainTaxRateResolverInterface::addResolver
ChainTaxRateResolver::getResolvers public function Gets all added resolvers. Overrides ChainTaxRateResolverInterface::getResolvers
ChainTaxRateResolver::resolve public function Resolves the tax rate for the given tax zone. Overrides TaxRateResolverInterface::resolve
ChainTaxRateResolver::__construct public function Constructs a new ChainTaxRateResolver object.
TaxRateResolverInterface::NO_APPLICABLE_TAX_RATE constant
TaxTypeAwareTrait::$taxType protected property The tax type.
TaxTypeAwareTrait::setTaxType public function