You are here

function uc_taxes_clone in Ubercart 6.2

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

Clones a tax rate.

1 string reference to 'uc_taxes_clone'
uc_taxes_menu in uc_taxes/uc_taxes.module
Implements hook_menu().

File

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

Code

function uc_taxes_clone($rate_id) {

  // 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.
  $rate = uc_taxes_rate_save($rate);

  // Clone the associated predicate as well.
  if ($predicate = ca_load_predicate('uc_taxes_' . $rate_id)) {
    $predicate['#pid'] = 'uc_taxes_' . $rate->id;
    ca_save_predicate($predicate);
  }

  // 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');
}