protected function getCategoryFieldName($node_type, $vid) {
    $fields = $this->entityFieldManager
      ->getFieldDefinitions('node', $node_type);

    // Determine which field is used for categories based on the configured
    // product node type.
    $category_field_name = FALSE;
    foreach ($fields as $field_name => $field_instance) {
      $field_type = $field_instance->getType();
      if ($field_type != 'entity_reference') {
        continue;
      }

      $settings = $field_instance->getSettings();
      if ($settings['target_type'] != 'taxonomy_term') {
        continue;
      }

      if (in_array($vid, $settings['handler_settings']['target_bundles'])) {
        $category_field_name = $field_name;
        break;
      }
    }

    return $category_field_name;
  }