Skip to content

Commit

Permalink
fix(core): Improve error message on populating without tax rates
Browse files Browse the repository at this point in the history
Fixes #1926
  • Loading branch information
michaelbromley committed Oct 14, 2024
1 parent 227da05 commit 7e36131
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 17 additions & 2 deletions packages/core/src/data-import/providers/importer/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RequestContext } from '../../../api/common/request-context';
import { InternalServerError } from '../../../common/error/errors';
import { ConfigService } from '../../../config/config.service';
import { CustomFieldConfig } from '../../../config/custom-field/custom-field-types';
import { Logger } from '../../../config/index';
import { Facet } from '../../../entity/facet/facet.entity';
import { FacetValue } from '../../../entity/facet-value/facet-value.entity';
import { TaxCategory } from '../../../entity/tax-category/tax-category.entity';
Expand Down Expand Up @@ -159,6 +160,17 @@ export class Importer {
let imported = 0;
const languageCode = ctx.languageCode;
const taxCategories = await this.taxCategoryService.findAll(ctx);
if (taxCategories.totalItems === 0) {
Logger.error(
[
`No TaxCategories found in the database. Ensure that at least one TaxCategory exists.`,
`If you are populating from an InitialData object, ensure the 'taxRates' array is not empty.`,
].join('\n'),
);
throw new Error(
`No TaxCategories found in the database. Ensure the IntialData.taxRates array is not empty.`,
);
}
await this.fastImporter.initialize(ctx.channel);
for (const { product, variants } of rows) {
const productMainTranslation = this.getTranslationByCodeOrFirst(
Expand Down Expand Up @@ -207,7 +219,7 @@ export class Importer {
);
const groupId = await this.fastImporter.createProductOptionGroup({
code,
options: optionGroupMainTranslation.values.map(name => ({} as any)),
options: optionGroupMainTranslation.values.map(name => ({}) as any),
translations: optionGroup.translations.map(translation => {
return {
languageCode: translation.languageCode,
Expand Down Expand Up @@ -363,7 +375,10 @@ export class Importer {
return facetValueIds;
}

protected processCustomFieldValues(customFields: { [field: string]: string }, config: CustomFieldConfig[]) {
protected processCustomFieldValues(
customFields: { [field: string]: string },
config: CustomFieldConfig[],
) {
const processed: { [field: string]: string | string[] | boolean | undefined } = {};
for (const fieldDef of config) {
const value = customFields[fieldDef.name];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ export class Populator {
taxRates: Array<{ name: string; percentage: number }>,
zoneMap: ZoneMap,
) {
const taxCategories: TaxCategory[] = [];

for (const taxRate of taxRates) {
const category = await this.taxCategoryService.create(ctx, { name: taxRate.name });

Expand Down

0 comments on commit 7e36131

Please sign in to comment.