function commerce_avatax_post_update_2 in Drupal Commerce Connector for AvaTax 8
Migrate back to using Configuration for managing AvaTax settings.
File
- ./
commerce_avatax.post_update.php, line 41 - Post update functions for Commerce AvaTax.
Code
function commerce_avatax_post_update_2() {
$entity_type_manager = Drupal::entityTypeManager();
// Pick the first available AvaTax tax plugin.
$tax_types = $entity_type_manager
->getStorage('commerce_tax_type')
->loadByProperties([
'plugin' => 'avatax',
]);
if (!$tax_types) {
return;
}
$tax_type = reset($tax_types);
$plugin_config = $tax_type
->getPluginConfiguration();
$config = \Drupal::service('config.factory')
->getEditable('commerce_avatax.settings');
$keys_to_migrate = [
'account_id',
'api_mode',
'company_code',
'disable_commit',
'license_key',
'shipping_tax_code',
];
foreach ($keys_to_migrate as $key) {
if (!isset($plugin_config[$key])) {
continue;
}
$config
->set($key, $plugin_config[$key]);
}
$config
->save();
}