You are here

function commerce_avatax_post_update_1 in Drupal Commerce Connector for AvaTax 8

Update old config data to tax type config.

File

./commerce_avatax.post_update.php, line 13
Post update functions for Commerce AvaTax.

Code

function commerce_avatax_post_update_1() {

  // Load old config.
  $config = \Drupal::service('config.factory')
    ->getEditable('commerce_avatax.settings');
  if ($config) {
    TaxType::create([
      'id' => 'avatax',
      'label' => 'AvaTax',
      'plugin' => 'avatax',
      'configuration' => [
        'display_inclusive' => FALSE,
        'account_id' => $config
          ->get('account_number'),
        'license_key' => $config
          ->get('license_key'),
        'company_code' => $config
          ->get('company_code'),
        'api_mode' => $config
          ->get('api_mode'),
        'tax_code' => $config
          ->get('tax_code'),
      ],
    ])
      ->save();

    // Delete old config.
    $config
      ->delete();
  }
}