You are here

function _commerce_avatax_configure_tax_exemption_field in Drupal Commerce Connector for AvaTax 7.5

Helper function : Configure the tax exemption field on users.

1 call to _commerce_avatax_configure_tax_exemption_field()
commerce_avatax_install_helper in ./commerce_avatax.install
Helper function to define and create the required fields & instances.

File

./commerce_avatax.install, line 177
Installation functions for Commerce Avatax module.

Code

function _commerce_avatax_configure_tax_exemption_field() {
  $field_name = COMMERCE_AVATAX_EXEMPTION_CODE_FIELD;
  $exemption_status = variable_get(COMMERCE_AVATAX_VAR_PREFIX . 'exemptions_status', 0);

  // Delete the field if it exist.
  if (!$exemption_status) {
    $instance = field_info_instance('user', $field_name, 'user');
    if ($instance) {
      field_delete_instance($instance);
    }
  }
  else {

    // Exemption status is YES.
    // Create the field and instance if they do not exist.
    $field = field_info_field($field_name);
    if (!$field) {
      field_create_field(array(
        'cardinality' => 1,
        'field_name' => $field_name,
        'settings' => array(
          'allowed_values_function' => 'commerce_avatax_exemption_codes_allowed_values',
        ),
        'type' => 'list_text',
      ));
    }
    $instance = field_info_instance('user', $field_name, 'user');
    if (!$instance) {
      field_create_instance(array(
        'bundle' => 'user',
        'display' => array(
          'default' => array(
            'label' => 'above',
            'module' => 'list',
            'settings' => array(),
            'type' => 'list_default',
            'weight' => 0,
          ),
        ),
        'entity_type' => 'user',
        'field_name' => $field_name,
        'label' => 'AvaTax Exemption Code',
        'required' => 0,
        'settings' => array(
          'user_register_form' => 0,
        ),
        'widget' => array(
          'active' => 1,
          'module' => 'options',
          'settings' => array(),
          'type' => 'options_select',
          'weight' => 7,
        ),
      ));
    }
  }
}