function uc_taxes_rate_load in Ubercart 7.3
Same name and namespace in other branches
- 6.2 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.
7 calls to uc_taxes_rate_load()
- hook_uc_calculate_tax in uc_taxes/
uc_taxes.api.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_clone in uc_taxes/
uc_taxes.admin.inc - Clones a tax rate.
- uc_taxes_default_rules_configuration in uc_taxes/
uc_taxes.rules_defaults.inc - Implements hook_default_rules_configuration().
- uc_taxes_delete_form in uc_taxes/
uc_taxes.admin.inc - Deletes a tax rule.
File
- uc_taxes/
uc_taxes.module, line 458 - Ubercart Taxes module.
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.
foreach ($result as $rate) {
$rate->taxed_product_types = array();
$rate->taxed_line_items = array();
$rates[$rate->id] = $rate;
}
foreach (array(
'taxed_product_types',
'taxed_line_items',
) as $field) {
$result = db_select('uc_' . $field, 't')
->fields('t', array(
'tax_id',
'type',
))
->execute();
foreach ($result as $record) {
$rates[$record->tax_id]->{$field}[] = $record->type;
}
}
}
// Return a rate as specified.
if ($rate_id) {
return isset($rates[$rate_id]) ? $rates[$rate_id] : FALSE;
}
else {
return $rates;
}
}