ChainTaxRateResolver.php in Commerce Core 8.2
File
modules/tax/src/Resolver/ChainTaxRateResolver.php
View source
<?php
namespace Drupal\commerce_tax\Resolver;
use Drupal\commerce_order\Entity\OrderItemInterface;
use Drupal\commerce_tax\TaxZone;
use Drupal\profile\Entity\ProfileInterface;
class ChainTaxRateResolver implements ChainTaxRateResolverInterface {
use TaxTypeAwareTrait;
protected $resolvers = [];
public function __construct(array $resolvers = []) {
$this->resolvers = $resolvers;
}
public function addResolver(TaxRateResolverInterface $resolver) {
$this->resolvers[] = $resolver;
}
public function getResolvers() {
return $this->resolvers;
}
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;
}
}