You are here

public function StoreTax::getDefaultRates in Commerce Core 8.2

Gets the default tax rates for the given store and order item.

Parameters

\Drupal\commerce_store\Entity\StoreInterface $store: The store.

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

Return value

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

Overrides StoreTaxInterface::getDefaultRates

File

modules/tax/src/StoreTax.php, line 103

Class

StoreTax

Namespace

Drupal\commerce_tax

Code

public function getDefaultRates(StoreInterface $store, OrderItemInterface $order_item) {
  $tax_type = $this
    ->getDefaultTaxType($store);
  if (!$tax_type) {
    return [];
  }
  $store_profile = $this
    ->buildStoreProfile($store);
  $rates = [];
  foreach ($this
    ->getDefaultZones($store) as $zone) {
    $this->chainRateResolver
      ->setTaxType($tax_type);
    $rate = $this->chainRateResolver
      ->resolve($zone, $order_item, $store_profile);
    if (is_object($rate)) {
      $rates[$zone
        ->getId()] = $rate;
    }
  }
  return $rates;
}