You are here

protected function LocalTaxTypeBase::resolveRates in Commerce Core 8.2

Resolves the tax rates for the given order item and customer profile.

Parameters

\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The order item.

\Drupal\profile\Entity\ProfileInterface $customer_profile: The customer profile. Contains the address and tax number.

Return value

\Drupal\commerce_tax\TaxRate[] The tax rates, keyed by tax zone ID.

1 call to LocalTaxTypeBase::resolveRates()
LocalTaxTypeBase::apply in modules/tax/src/Plugin/Commerce/TaxType/LocalTaxTypeBase.php
Applies the tax type to the given order.

File

modules/tax/src/Plugin/Commerce/TaxType/LocalTaxTypeBase.php, line 235

Class

LocalTaxTypeBase
Provides the base class for local tax types.

Namespace

Drupal\commerce_tax\Plugin\Commerce\TaxType

Code

protected function resolveRates(OrderItemInterface $order_item, ProfileInterface $customer_profile) {
  $zones = $this
    ->resolveZones($order_item, $customer_profile);
  if (!$zones) {
    return [];
  }

  // Provide the tax type entity to the resolvers.
  $this->chainRateResolver
    ->setTaxType($this->parentEntity);
  $rates = [];
  foreach ($zones as $zone) {
    $rate = $this->chainRateResolver
      ->resolve($zone, $order_item, $customer_profile);
    if (is_object($rate)) {
      $rates[$zone
        ->getId()] = $rate;
    }
  }
  return $rates;
}