You are here

function commerce_avatax_update_8104 in Drupal Commerce Connector for AvaTax 8

Add the customer exemptions fields to the user.

File

./commerce_avatax.install, line 44
Provides install and update hooks for Commerce AvaTax.

Code

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) {
    }
  }
}