You are here

function uc_taxes_clone in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_taxes/uc_taxes.admin.inc \uc_taxes_clone()

Clones a tax rate.

2 string references to 'uc_taxes_clone'
uc_taxes_admin_settings in uc_taxes/uc_taxes.admin.inc
Displays a list of tax rates.
uc_taxes_menu in uc_taxes/uc_taxes.module
Implements hook_menu().

File

uc_taxes/uc_taxes.admin.inc, line 214
Taxes administration menu items.

Code

function uc_taxes_clone($rate_id) {
  if (!isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'uc_taxes_clone')) {
    return MENU_ACCESS_DENIED;
  }

  // Load the source rate object.
  $rate = uc_taxes_rate_load($rate_id);
  $name = $rate->name;

  // Tweak the name and unset the rate ID.
  $rate->name = t('Copy of !name', array(
    '!name' => $rate->name,
  ));
  $rate->id = NULL;

  // Save the new rate without clearing the Rules cache.
  $rate = uc_taxes_rate_save($rate, FALSE);

  // Clone the associated conditions as well.
  if ($conditions = rules_config_load('uc_taxes_' . $rate_id)) {
    $conditions->id = NULL;
    $conditions->name = '';
    $conditions
      ->save('uc_taxes_' . $rate->id);
  }
  entity_flush_caches();

  // Display a message and redirect back to the overview.
  drupal_set_message(t('Tax rate %name cloned.', array(
    '%name' => $name,
  )));
  drupal_goto('admin/store/settings/taxes');
}