You are here

function uc_taxes_rate_load in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_taxes/uc_taxes.module \uc_taxes_rate_load()

Loads a tax rate or all tax rates from the database.

Parameters

$rate_id: The ID of the specific rate to load or NULL to return all available rates.

Return value

An object representing the requested tax rate or an array of all tax rates keyed by rate ID.

8 calls to uc_taxes_rate_load()
hook_calculate_tax in docs/hooks.php
Calculates tax line items for an order.
uc_taxes_admin_settings in uc_taxes/uc_taxes.admin.inc
Displays a list of tax rates.
uc_taxes_calculate_tax in uc_taxes/uc_taxes.module
Calculates the amount and types of taxes that apply to an order.
uc_taxes_ca_action in uc_taxes/uc_taxes.ca.inc
Implements hook_action_info().
uc_taxes_ca_predicate in uc_taxes/uc_taxes.ca.inc
Implements hook_ca_predicate().

... See full list

File

uc_taxes/uc_taxes.module, line 325

Code

function uc_taxes_rate_load($rate_id = NULL) {
  static $rates = array();

  // If the rates have not been cached yet...
  if (empty($rates)) {

    // Get all the rate data from the database.
    $result = db_query("SELECT * FROM {uc_taxes} ORDER BY weight");

    // Loop through each returned row.
    while ($rate = db_fetch_object($result)) {

      // Unserialize some arrays and cache the rate in a static array.
      $rate->taxed_product_types = unserialize($rate->taxed_product_types);
      $rate->taxed_line_items = unserialize($rate->taxed_line_items);
      $rates[$rate->id] = $rate;
    }
  }

  // Return a rate as specified.
  if ($rate_id) {
    return $rates[$rate_id];
  }
  else {
    return $rates;
  }
}