You are here

function commerce_tax_ui_tax_rate_save in Commerce Core 7

Saves a tax rate.

This function will either insert a new tax rate if $tax_rate['is_new'] is set or attempt to update an existing tax rate if it is not. It does not currently support changing the machine-name of the tax rate, nor is this possible through the form supplied by the Tax UI module.

Parameters

$tax_rate: The tax rate array containing the basic properties as initialized in commerce_tax_ui_tax_rate_new().

$skip_reset: Boolean indicating whether or not this save should result in entities being reset and the menu being rebuilt; defaults to FALSE. This is useful when you intend to perform many d at once, as menu rebuilding is very costly in terms of performance.

Return value

The return value of the call to drupal_write_record() to save the tax rate, either FALSE on failure or SAVED_NEW or SAVED_UPDATED indicating the rate of query performed to save the tax rate.

2 calls to commerce_tax_ui_tax_rate_save()
CommerceBaseTestCase::createDummyTaxRate in tests/commerce_base.test
* Create a dummy tax rate. * *
commerce_tax_ui_tax_rate_form_submit in modules/tax/includes/commerce_tax_ui.admin.inc
Form submit handler: save a tax rate.

File

modules/tax/commerce_tax_ui.module, line 405
Provides a UI for creating simple tax types and rates.

Code

function commerce_tax_ui_tax_rate_save($tax_rate, $skip_reset = FALSE) {
  $op = drupal_write_record('commerce_tax_rate', $tax_rate, empty($tax_rate['is_new']) ? 'name' : array());
  commerce_tax_rates_reset();

  // If this is a new tax rate and the insert did not fail...
  if (!empty($tax_rate['is_new']) && $op !== FALSE) {

    // Notify other modules that a new tax rate has been created.
    module_invoke_all('commerce_tax_rate_insert', $tax_rate, $skip_reset);
  }
  elseif ($op !== FALSE) {

    // Notify other modules that an existing tax rate has been updated.
    module_invoke_all('commerce_tax_rate_update', $tax_rate, $skip_reset);
  }

  // Clear the necessary caches and rebuild the menu items.
  if (!$skip_reset) {
    entity_defaults_rebuild();
    rules_clear_cache(TRUE);
    variable_set('menu_rebuild_needed', TRUE);
  }
  return $op;
}