You are here

commerce_avatax.install in Drupal Commerce Connector for AvaTax 7.4

Installation functions for Commerce AvaTax Connector.

File

commerce_avatax.install
View source
<?php

/**
 * @file
 * Installation functions for Commerce AvaTax Connector.
 */

/**
 * Implements hook_update().
 */
function commerce_avatax_update_7401() {
  $company_code = variable_get('commerce_avatax_company_code');
  if ($company_code) {
    $product_version = variable_get('commerce_avatax_product_version');
    $use_mode = variable_get('commerce_avatax_use_mode');
    $update = $company_code;
    $update_var_name = 'commerce_avatax_' . $product_version . '_' . $use_mode . '_company';
    variable_set($update_var_name, $update);
    variable_del('commerce_avatax_company_code');
  }
  $country = variable_get('commerce_avatax_primary_country');
  if (!$country) {
    $country = 'US';
    $update = $country;
    $update_var_name = 'commerce_avatax_primary_country';
    variable_set($update_var_name, $update);
  }
  $account_name = variable_get('commerce_avatax_account_name');
  if (!$account_name) {
    $account_name = variable_get('site_name');
    $update = $account_name;
    $update_var_name = 'commerce_avatax_account_name';
    variable_set($update_var_name, $update);
  }
}

/**
 * Implements hook_requirements().
 */
function commerce_avatax_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time.
  $t = get_t();
  $has_curl = extension_loaded('curl');
  $requirements['commerce_avatax_curl'] = array(
    'title' => $t('cURL'),
    'value' => $has_curl ? $t('Enabled for Commerce AvaTax') : $t('Not found'),
  );
  if (!$has_curl) {
    $requirements['commerce_avatax_curl']['severity'] = REQUIREMENT_ERROR;
    $requirements['commerce_avatax_curl']['description'] = $t('Commerce AvaTax requires PHP cURL extension to be enabled and configured on your server.');
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function commerce_avatax_install() {
  variable_set('commerce_avatax_install_time', microtime(TRUE));
  if (module_exists('commerce_tax')) {
    $t = get_t();
    drupal_set_message($t('Commerce AvaTax may conflict with the commerce_tax module.'), 'warning');
  }
}

/**
 * Implements hook_uninstall().
 */
function commerce_avatax_uninstall() {

  // Delete AvaTax variables.
  db_delete('variable')
    ->condition('name', "commerce_avatax_%", "LIKE")
    ->execute();
  cache_clear_all('variables', 'cache');

  // Delete AvaTax rules.
  $rules = rules_config_load_multiple(FALSE);
  foreach ($rules as $rule) {
    if (strpos($rule->name, 'commerce_avatax') === 0) {
      rules_config_delete(array(
        $rule->id,
      ));
    }
  }
}