You are here

commerce_avatax.install in Drupal Commerce Connector for AvaTax 8

Provides install and update hooks for Commerce AvaTax.

File

commerce_avatax.install
View source
<?php

/**
 * @file
 * Provides install and update hooks for Commerce AvaTax.
 */
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Field\BaseFieldDefinition;

/**
 * Add the "customer_code_field" setting.
 */
function commerce_avatax_update_8101() {
  $config = \Drupal::configFactory()
    ->getEditable('commerce_avatax.settings');
  $config
    ->set('customer_code_field', 'mail')
    ->save();
}

/**
 * Add the "logging" setting.
 */
function commerce_avatax_update_8102() {
  $config = \Drupal::configFactory()
    ->getEditable('commerce_avatax.settings');
  $config
    ->set('logging', FALSE)
    ->save();
}

/**
 * Add the "disable_tax_calculation" setting.
 */
function commerce_avatax_update_8103() {
  $config = \Drupal::configFactory()
    ->getEditable('commerce_avatax.settings');
  $config
    ->set('disable_tax_calculation', FALSE)
    ->save();
}

/**
 * Add the customer exemptions fields to the user.
 */
function commerce_avatax_update_8104() {
  $entity_definition_update = \Drupal::entityDefinitionUpdateManager();
  $fields = [];
  $fields['avatax_customer_code'] = BaseFieldDefinition::create('string')
    ->setLabel(t('AvaTax customer code'))
    ->setDisplayConfigurable('form', TRUE)
    ->setSetting('max_length', 50)
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ]);
  $fields['avatax_tax_exemption_number'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Tax Exemption number'))
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ]);
  $fields['avatax_tax_exemption_type'] = BaseFieldDefinition::create('list_string')
    ->setLabel(t('Tax Exemption type'))
    ->setSetting('allowed_values_function', [
    '\\Drupal\\commerce_avatax\\Avatax',
    'getExemptionTypes',
  ])
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 4,
  ])
    ->setDisplayConfigurable('form', TRUE);
  foreach ($fields as $name => $definition) {
    try {
      $entity_definition_update
        ->installFieldStorageDefinition($name, 'user', 'commerce_avatax', $definition);
    } catch (EntityStorageException $e) {
    }
  }
}

Functions

Namesort descending Description
commerce_avatax_update_8101 Add the "customer_code_field" setting.
commerce_avatax_update_8102 Add the "logging" setting.
commerce_avatax_update_8103 Add the "disable_tax_calculation" setting.
commerce_avatax_update_8104 Add the customer exemptions fields to the user.