You are here

function uc_taxes_filter_rates in Ubercart 7.3

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

$order: The order that taxes are being calculated for.

2 calls to uc_taxes_filter_rates()
uc_taxes_get_included_tax in uc_taxes/uc_taxes.module
Calculates the taxes that should be included in a product's display price.
uc_taxes_uc_calculate_tax in uc_taxes/uc_taxes.module
Calculates the amount and types of taxes that apply to an order.

File

uc_taxes/uc_taxes.module, line 405
Ubercart Taxes module.

Code

function uc_taxes_filter_rates($order) {
  $taxes = array();

  // If no order, then just return all rates.
  if (empty($order)) {
    $taxes = uc_taxes_rate_load();
  }
  elseif (isset($order->order_status) && uc_order_status_data($order->order_status, 'state') != '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_taxes_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_taxes_rate_load() as $rate) {
      $tax = clone $rate;
      if (rules_invoke_component('uc_taxes_' . $tax->id, $order)) {
        $taxes[] = $tax;
      }
    }
  }
  return $taxes;
}