You are here

function uc_tax_filter_rates in Ubercart 8.4

List all the taxes that can apply to an order.

The taxes depend on the order status. For orders which are still in checkout, any tax can apply. For orders out of checkout, only taxes originally saved as line items can apply.

Parameters

\Drupal\uc_order\OrderInterface $order: The order that taxes are being calculated for.

2 calls to uc_tax_filter_rates()
uc_tax_get_included_tax in uc_tax/uc_tax.module
Calculates the taxes that should be included in a product's display price.
uc_tax_uc_calculate_tax in uc_tax/uc_tax.module
Calculates the amount and types of taxes that apply to an order.

File

uc_tax/uc_tax.module, line 278
Ubercart Tax module.

Code

function uc_tax_filter_rates(OrderInterface $order = NULL) {
  $taxes = [];

  // If no order, then just return all rates.
  if (empty($order)) {
    $taxes = uc_tax_rate_load();
  }
  elseif ($order
    ->getStateId() != 'in_checkout') {
    if (isset($order->line_items)) {
      foreach ($order->line_items as $item) {
        if ($item['type'] == 'tax') {
          if (!empty($item['data']['tax'])) {

            // Use the rate stored in the line-item.
            $taxes[] = clone $item['data']['tax'];
          }
          elseif (!empty($item['data']['tax_id']) && ($tax = uc_tax_rate_load($item['data']['tax_id']))) {

            // For old orders that don't have all the tax info, all we can do
            // is preserve the rate.
            $tax = clone $tax;
            if (!empty($item['data']['tax_rate'])) {
              $tax->rate = $item['data']['tax_rate'];
            }
            $taxes[] = $tax;
          }
        }
      }
    }
  }
  else {
    foreach (uc_tax_rate_load() as $rate) {
      $tax = clone $rate;

      // if (rules_invoke_component('uc_tax_' . $tax->id, $order)) {
      $taxes[] = $tax;

      // }
    }
  }
  return $taxes;
}