uc_taxes_rate_save
Drupal 7 uc_taxes_rate_save($rate)
Saves a tax rate to the database.
Parameters
$rate: The tax rate object to be saved.
Return value
The saved tax rate object including the rate ID for new rates.
4 calls to uc_taxes_rate_save()
File
- sites/
all/ modules/ ubercart/ uc_taxes/ uc_taxes.module, line 332 - Ubercart Taxes module.
Code
function uc_taxes_rate_save($rate) {
// Save it as a new rate if no ID is specified.
if (!$rate->id) {
drupal_write_record('uc_taxes', $rate);
}
// Otherwise update the existing tax rate's data.
else {
drupal_write_record('uc_taxes', $rate, array('id'));
}
db_delete('uc_taxed_product_types')
->condition('tax_id', $rate->id)
->execute();
db_delete('uc_taxed_line_items')
->condition('tax_id', $rate->id)
->execute();
$p_insert = db_insert('uc_taxed_product_types')->fields(array('tax_id', 'type'));
$l_insert = db_insert('uc_taxed_line_items')->fields(array('tax_id', 'type'));
foreach ($rate->taxed_product_types as $type) {
$p_insert->values(array(
'tax_id' => $rate->id,
'type' => $type,
));
}
foreach ($rate->taxed_line_items as $type) {
$l_insert->values(array(
'tax_id' => $rate->id,
'type' => $type,
));
}
$p_insert->execute();
$l_insert->execute();
// Ensure Rules picks up the new condition.
entity_flush_caches();
return $rate;
}

