You are here

public function TaxRateResolver::resolve in Commerce Core 8.2

Resolves the tax rate for the given tax zone.

Parameters

\Drupal\commerce_tax\TaxZone $zone: The tax zone.

\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|string|null The tax rate, NO_APPLICABLE_TAX_RATE, or NULL.

Overrides TaxRateResolverInterface::resolve

File

modules/tax/tests/modules/commerce_tax_test/src/Resolver/TaxRateResolver.php, line 21

Class

TaxRateResolver

Namespace

Drupal\commerce_tax_test\Resolver

Code

public function resolve(TaxZone $zone, OrderItemInterface $order_item, ProfileInterface $customer_profile) {

  // Confirm that a tax type is always set.
  assert($this->taxType instanceof TaxTypeInterface);

  // Use the "reduced" rate for order items with a quantity larger than 20.
  if (Calculator::compare($order_item
    ->getQuantity(), '20') == 1) {
    return $zone
      ->getRate('reduced') ?: $zone
      ->getDefaultRate();
  }
}