Browse Source

fix(core): Use configured defaultLanguageCode rather than hard-coded val

Relates to #296
Michael Bromley 5 years ago
parent
commit
d2942e6b99

+ 5 - 8
packages/core/src/api/common/request-context.service.ts

@@ -66,7 +66,7 @@ export class RequestContextService {
     }
 
     private getLanguageCode(req: Request): LanguageCode | undefined {
-        return req.query && req.query.languageCode;
+        return (req.query && req.query.languageCode) || this.configService.defaultLanguageCode;
     }
 
     private isAuthenticatedSession(session?: Session): session is AuthenticatedSession {
@@ -82,7 +82,7 @@ export class RequestContextService {
             return false;
         }
         const permissionsOnChannel = user.roles
-            .filter(role => role.channels.find(c => idsAreEqual(c.id, channel.id)))
+            .filter((role) => role.channels.find((c) => idsAreEqual(c.id, channel.id)))
             .reduce((output, role) => [...output, ...role.permissions], [] as Permission[]);
         return this.arraysIntersect(permissions, permissionsOnChannel);
     }
@@ -91,11 +91,8 @@ export class RequestContextService {
      * Returns true if any element of arr1 appears in arr2.
      */
     private arraysIntersect<T>(arr1: T[], arr2: T[]): boolean {
-        return arr1.reduce(
-            (intersects, role) => {
-                return intersects || arr2.includes(role);
-            },
-            false as boolean,
-        );
+        return arr1.reduce((intersects, role) => {
+            return intersects || arr2.includes(role);
+        }, false as boolean);
     }
 }

+ 1 - 4
packages/core/src/api/common/request-context.ts

@@ -2,13 +2,11 @@ import { LanguageCode } from '@vendure/common/lib/generated-types';
 import { ID, JsonCompatible } from '@vendure/common/lib/shared-types';
 import { TFunction } from 'i18next';
 
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { Channel } from '../../entity/channel/channel.entity';
 import { AnonymousSession } from '../../entity/session/anonymous-session.entity';
 import { AuthenticatedSession } from '../../entity/session/authenticated-session.entity';
 import { Session } from '../../entity/session/session.entity';
 import { User } from '../../entity/user/user.entity';
-import { JobData } from '../../job-queue/types';
 
 import { ApiType } from './get-api-type';
 
@@ -55,8 +53,7 @@ export class RequestContext {
         this._apiType = apiType;
         this._channel = channel;
         this._session = session;
-        this._languageCode =
-            languageCode || (channel && channel.defaultLanguageCode) || DEFAULT_LANGUAGE_CODE;
+        this._languageCode = languageCode || (channel && channel.defaultLanguageCode);
         this._isAuthorized = options.isAuthorized;
         this._authorizedAsOwnerOnly = options.authorizedAsOwnerOnly;
         this._translationFn = translationFn || (((key: string) => key) as any);

+ 3 - 5
packages/core/src/api/common/validate-custom-field-value.ts

@@ -1,7 +1,6 @@
 import { LanguageCode } from '@vendure/common/lib/generated-types';
 import { assertNever } from '@vendure/common/lib/shared-utils';
 
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { UserInputError } from '../../common/error/errors';
 import {
     CustomFieldConfig,
@@ -63,8 +62,7 @@ function validateCustomFunction<T extends TypedCustomFieldConfig<any, any>>(
             throw new UserInputError(error);
         }
         if (Array.isArray(error)) {
-            const localizedError =
-                error.find(e => e.languageCode === (languageCode || DEFAULT_LANGUAGE_CODE)) || error[0];
+            const localizedError = error.find((e) => e.languageCode === languageCode) || error[0];
             throw new UserInputError(localizedError.value);
         }
     }
@@ -87,12 +85,12 @@ function validateStringField(
     }
     const options = (config as StringCustomFieldConfig).options;
     if (options) {
-        const validOptions = options.map(o => o.value);
+        const validOptions = options.map((o) => o.value);
         if (!validOptions.includes(value)) {
             throw new UserInputError('error.field-invalid-string-option', {
                 name: config.name,
                 value,
-                validOptions: validOptions.map(o => `'${o}'`).join(', '),
+                validOptions: validOptions.map((o) => `'${o}'`).join(', '),
             });
         }
     }

+ 10 - 6
packages/core/src/api/resolvers/admin/facet.resolver.ts

@@ -13,9 +13,9 @@ import {
 } from '@vendure/common/lib/generated-types';
 import { PaginatedList } from '@vendure/common/lib/shared-types';
 
-import { DEFAULT_LANGUAGE_CODE } from '../../../common/constants';
 import { EntityNotFoundError } from '../../../common/error/errors';
 import { Translated } from '../../../common/types/locale-types';
+import { ConfigService } from '../../../config/config.service';
 import { FacetValue } from '../../../entity/facet-value/facet-value.entity';
 import { Facet } from '../../../entity/facet/facet.entity';
 import { FacetValueService } from '../../../service/services/facet-value.service';
@@ -26,7 +26,11 @@ import { Ctx } from '../../decorators/request-context.decorator';
 
 @Resolver('Facet')
 export class FacetResolver {
-    constructor(private facetService: FacetService, private facetValueService: FacetValueService) {}
+    constructor(
+        private facetService: FacetService,
+        private facetValueService: FacetValueService,
+        private configService: ConfigService,
+    ) {}
 
     @Query()
     @Allow(Permission.ReadCatalog)
@@ -84,11 +88,11 @@ export class FacetResolver {
     ): Promise<Array<Translated<FacetValue>>> {
         const { input } = args;
         const facetId = input[0].facetId;
-        const facet = await this.facetService.findOne(facetId, DEFAULT_LANGUAGE_CODE);
+        const facet = await this.facetService.findOne(facetId, this.configService.defaultLanguageCode);
         if (!facet) {
             throw new EntityNotFoundError('Facet', facetId);
         }
-        return Promise.all(input.map(facetValue => this.facetValueService.create(facet, facetValue)));
+        return Promise.all(input.map((facetValue) => this.facetValueService.create(facet, facetValue)));
     }
 
     @Mutation()
@@ -97,7 +101,7 @@ export class FacetResolver {
         @Args() args: MutationUpdateFacetValuesArgs,
     ): Promise<Array<Translated<FacetValue>>> {
         const { input } = args;
-        return Promise.all(input.map(facetValue => this.facetValueService.update(facetValue)));
+        return Promise.all(input.map((facetValue) => this.facetValueService.update(facetValue)));
     }
 
     @Mutation()
@@ -106,6 +110,6 @@ export class FacetResolver {
         @Ctx() ctx: RequestContext,
         @Args() args: MutationDeleteFacetValuesArgs,
     ): Promise<DeletionResponse[]> {
-        return Promise.all(args.ids.map(id => this.facetValueService.delete(ctx, id, args.force || false)));
+        return Promise.all(args.ids.map((id) => this.facetValueService.delete(ctx, id, args.force || false)));
     }
 }

+ 4 - 0
packages/core/src/common/constants.ts

@@ -1,3 +1,7 @@
 import { LanguageCode } from '@vendure/common/lib/generated-types';
 
+/**
+ * This value should be rarely used - only in those contexts where we have no access to the
+ * VendureConfig to ensure at least a valid LanguageCode is available.
+ */
 export const DEFAULT_LANGUAGE_CODE = LanguageCode.en;

+ 0 - 1
packages/core/src/service/helpers/utils/translate-entity.spec.ts

@@ -1,6 +1,5 @@
 import { LanguageCode } from '@vendure/common/lib/generated-types';
 
-import { DEFAULT_LANGUAGE_CODE } from '../../../common/constants';
 import { Translatable, Translation } from '../../../common/types/locale-types';
 import { VendureEntity } from '../../../entity/base/base.entity';
 import { CollectionTranslation } from '../../../entity/collection/collection-translation.entity';

+ 5 - 6
packages/core/src/service/services/channel.service.ts

@@ -13,7 +13,6 @@ import { unique } from '@vendure/common/lib/unique';
 import { Connection } from 'typeorm';
 
 import { RequestContext } from '../../api/common/request-context';
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { ChannelNotFoundError, EntityNotFoundError, InternalServerError } from '../../common/error/errors';
 import { ChannelAware } from '../../common/types/common-types';
 import { assertFound, idsAreEqual } from '../../common/utils';
@@ -46,7 +45,7 @@ export class ChannelService {
      */
     assignToCurrentChannel<T extends ChannelAware>(entity: T, ctx: RequestContext): T {
         const channelIds = unique([ctx.channelId, this.getDefaultChannel().id]);
-        entity.channels = channelIds.map(id => ({ id })) as any;
+        entity.channels = channelIds.map((id) => ({ id })) as any;
         return entity;
     }
 
@@ -81,7 +80,7 @@ export class ChannelService {
             relations: ['channels'],
         });
         for (const id of channelIds) {
-            entity.channels = entity.channels.filter(c => !idsAreEqual(c.id, id));
+            entity.channels = entity.channels.filter((c) => !idsAreEqual(c.id, id));
         }
         await this.connection.getRepository(entityType).save(entity as any, { reload: false });
         return entity;
@@ -95,7 +94,7 @@ export class ChannelService {
             // there is only the default channel, so return it
             return this.getDefaultChannel();
         }
-        const channel = this.allChannels.find(c => c.token === token);
+        const channel = this.allChannels.find((c) => c.token === token);
         if (!channel) {
             throw new ChannelNotFoundError(token);
         }
@@ -106,7 +105,7 @@ export class ChannelService {
      * Returns the default Channel.
      */
     getDefaultChannel(): Channel {
-        const defaultChannel = this.allChannels.find(channel => channel.code === DEFAULT_CHANNEL_CODE);
+        const defaultChannel = this.allChannels.find((channel) => channel.code === DEFAULT_CHANNEL_CODE);
 
         if (!defaultChannel) {
             throw new InternalServerError(`error.default-channel-not-found`);
@@ -194,7 +193,7 @@ export class ChannelService {
         if (!defaultChannel) {
             const newDefaultChannel = new Channel({
                 code: DEFAULT_CHANNEL_CODE,
-                defaultLanguageCode: DEFAULT_LANGUAGE_CODE,
+                defaultLanguageCode: this.configService.defaultLanguageCode,
                 pricesIncludeTax: false,
                 currencyCode: CurrencyCode.USD,
                 token: defaultChannelToken,

+ 3 - 2
packages/core/src/service/services/collection.service.ts

@@ -18,7 +18,6 @@ import { Connection } from 'typeorm';
 
 import { RequestContext, SerializedRequestContext } from '../../api/common/request-context';
 import { configurableDefToOperation } from '../../common/configurable-operation';
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { IllegalOperationError, UserInputError } from '../../common/error/errors';
 import { ListQueryOptions } from '../../common/types/common-types';
 import { Translated } from '../../common/types/locale-types';
@@ -28,6 +27,7 @@ import {
     facetValueCollectionFilter,
     variantNameCollectionFilter,
 } from '../../config/collection/default-collection-filters';
+import { ConfigService } from '../../config/config.service';
 import { Logger } from '../../config/logger/vendure-logger';
 import { CollectionTranslation } from '../../entity/collection/collection-translation.entity';
 import { Collection } from '../../entity/collection/collection.entity';
@@ -70,6 +70,7 @@ export class CollectionService implements OnModuleInit {
         private eventBus: EventBus,
         private workerService: WorkerService,
         private jobQueueService: JobQueueService,
+        private configService: ConfigService,
     ) {}
 
     onModuleInit() {
@@ -483,7 +484,7 @@ export class CollectionService implements OnModuleInit {
 
         const rootTranslation = await this.connection.getRepository(CollectionTranslation).save(
             new CollectionTranslation({
-                languageCode: DEFAULT_LANGUAGE_CODE,
+                languageCode: this.configService.defaultLanguageCode,
                 name: ROOT_COLLECTION_NAME,
                 description: 'The root of the Collection tree.',
             }),

+ 11 - 8
packages/core/src/service/services/facet-value.service.ts

@@ -12,9 +12,9 @@ import { ID } from '@vendure/common/lib/shared-types';
 import { Connection } from 'typeorm';
 
 import { RequestContext } from '../../api/common/request-context';
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { Translated } from '../../common/types/locale-types';
 import { assertFound } from '../../common/utils';
+import { ConfigService } from '../../config/config.service';
 import { Product, ProductVariant } from '../../entity';
 import { FacetValueTranslation } from '../../entity/facet-value/facet-value-translation.entity';
 import { FacetValue } from '../../entity/facet-value/facet-value.entity';
@@ -28,6 +28,7 @@ export class FacetValueService {
     constructor(
         @InjectConnection() private connection: Connection,
         private translatableSaver: TranslatableSaver,
+        private configService: ConfigService,
     ) {}
 
     findAll(lang: LanguageCode): Promise<Array<Translated<FacetValue>>> {
@@ -35,7 +36,9 @@ export class FacetValueService {
             .find(FacetValue, {
                 relations: ['facet'],
             })
-            .then(facetValues => facetValues.map(facetValue => translateDeep(facetValue, lang, ['facet'])));
+            .then((facetValues) =>
+                facetValues.map((facetValue) => translateDeep(facetValue, lang, ['facet'])),
+            );
     }
 
     findOne(id: ID, lang: LanguageCode): Promise<Translated<FacetValue> | undefined> {
@@ -43,7 +46,7 @@ export class FacetValueService {
             .findOne(FacetValue, id, {
                 relations: ['facet'],
             })
-            .then(facetValue => facetValue && translateDeep(facetValue, lang, ['facet']));
+            .then((facetValue) => facetValue && translateDeep(facetValue, lang, ['facet']));
     }
 
     findByIds(ids: ID[]): Promise<FacetValue[]>;
@@ -53,8 +56,8 @@ export class FacetValueService {
             .getRepository(FacetValue)
             .findByIds(ids, { relations: ['facet'] });
         if (lang) {
-            return facetValues.then(values =>
-                values.map(facetValue => translateDeep(facetValue, lang, ['facet'])),
+            return facetValues.then((values) =>
+                values.map((facetValue) => translateDeep(facetValue, lang, ['facet'])),
             );
         } else {
             return facetValues;
@@ -69,9 +72,9 @@ export class FacetValueService {
             input,
             entityType: FacetValue,
             translationType: FacetValueTranslation,
-            beforeSave: fv => (fv.facet = facet),
+            beforeSave: (fv) => (fv.facet = facet),
         });
-        return assertFound(this.findOne(facetValue.id, DEFAULT_LANGUAGE_CODE));
+        return assertFound(this.findOne(facetValue.id, this.configService.defaultLanguageCode));
     }
 
     async update(input: UpdateFacetValueInput): Promise<Translated<FacetValue>> {
@@ -80,7 +83,7 @@ export class FacetValueService {
             entityType: FacetValue,
             translationType: FacetValueTranslation,
         });
-        return assertFound(this.findOne(facetValue.id, DEFAULT_LANGUAGE_CODE));
+        return assertFound(this.findOne(facetValue.id, this.configService.defaultLanguageCode));
     }
 
     async delete(ctx: RequestContext, id: ID, force: boolean = false): Promise<DeletionResponse> {

+ 8 - 9
packages/core/src/service/services/facet.service.ts

@@ -11,10 +11,10 @@ import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
 import { Connection } from 'typeorm';
 
 import { RequestContext } from '../../api/common/request-context';
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { ListQueryOptions } from '../../common/types/common-types';
 import { Translated } from '../../common/types/locale-types';
 import { assertFound } from '../../common/utils';
+import { ConfigService } from '../../config/config.service';
 import { FacetTranslation } from '../../entity/facet/facet-translation.entity';
 import { Facet } from '../../entity/facet/facet.entity';
 import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
@@ -31,6 +31,7 @@ export class FacetService {
         private facetValueService: FacetValueService,
         private translatableSaver: TranslatableSaver,
         private listQueryBuilder: ListQueryBuilder,
+        private configService: ConfigService,
     ) {}
 
     findAll(
@@ -43,7 +44,7 @@ export class FacetService {
             .build(Facet, options, { relations })
             .getManyAndCount()
             .then(([facets, totalItems]) => {
-                const items = facets.map(facet =>
+                const items = facets.map((facet) =>
                     translateDeep(facet, lang, ['values', ['values', 'facet']]),
                 );
                 return {
@@ -58,7 +59,7 @@ export class FacetService {
 
         return this.connection.manager
             .findOne(Facet, facetId, { relations })
-            .then(facet => facet && translateDeep(facet, lang, ['values', ['values', 'facet']]));
+            .then((facet) => facet && translateDeep(facet, lang, ['values', ['values', 'facet']]));
     }
 
     findByCode(facetCode: string, lang: LanguageCode): Promise<Translated<Facet> | undefined> {
@@ -71,7 +72,7 @@ export class FacetService {
                 },
                 relations,
             })
-            .then(facet => facet && translateDeep(facet, lang, ['values', ['values', 'facet']]));
+            .then((facet) => facet && translateDeep(facet, lang, ['values', ['values', 'facet']]));
     }
 
     async create(input: CreateFacetInput): Promise<Translated<Facet>> {
@@ -80,7 +81,7 @@ export class FacetService {
             entityType: Facet,
             translationType: FacetTranslation,
         });
-        return assertFound(this.findOne(facet.id, DEFAULT_LANGUAGE_CODE));
+        return assertFound(this.findOne(facet.id, this.configService.defaultLanguageCode));
     }
 
     async update(input: UpdateFacetInput): Promise<Translated<Facet>> {
@@ -89,7 +90,7 @@ export class FacetService {
             entityType: Facet,
             translationType: FacetTranslation,
         });
-        return assertFound(this.findOne(facet.id, DEFAULT_LANGUAGE_CODE));
+        return assertFound(this.findOne(facet.id, this.configService.defaultLanguageCode));
     }
 
     async delete(ctx: RequestContext, id: ID, force: boolean = false): Promise<DeletionResponse> {
@@ -97,9 +98,7 @@ export class FacetService {
         let productCount = 0;
         let variantCount = 0;
         if (facet.values.length) {
-            const counts = await this.facetValueService.checkFacetValueUsage(
-                facet.values.map(fv => fv.id),
-            );
+            const counts = await this.facetValueService.checkFacetValueUsage(facet.values.map((fv) => fv.id));
             productCount = counts.productCount;
             variantCount = counts.variantCount;
         }

+ 3 - 3
packages/core/src/service/services/global-settings.service.ts

@@ -3,14 +3,14 @@ import { InjectConnection } from '@nestjs/typeorm';
 import { UpdateGlobalSettingsInput } from '@vendure/common/lib/generated-types';
 import { Connection } from 'typeorm';
 
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { InternalServerError } from '../../common/error/errors';
+import { ConfigService } from '../../config/config.service';
 import { GlobalSettings } from '../../entity/global-settings/global-settings.entity';
 import { patchEntity } from '../helpers/utils/patch-entity';
 
 @Injectable()
 export class GlobalSettingsService {
-    constructor(@InjectConnection() private connection: Connection) {}
+    constructor(@InjectConnection() private connection: Connection, private configService: ConfigService) {}
 
     /**
      * Ensure there is a global settings row in the database.
@@ -20,7 +20,7 @@ export class GlobalSettingsService {
             await this.getSettings();
         } catch (err) {
             const settings = new GlobalSettings({
-                availableLanguages: [DEFAULT_LANGUAGE_CODE],
+                availableLanguages: [this.configService.defaultLanguageCode],
             });
             await this.connection.getRepository(GlobalSettings).save(settings, { reload: false });
         }

+ 8 - 5
packages/core/src/service/services/product-option.service.ts

@@ -1,11 +1,14 @@
 import { Injectable } from '@nestjs/common';
 import { InjectConnection } from '@nestjs/typeorm';
-import { CreateGroupOptionInput, CreateProductOptionInput, LanguageCode, UpdateProductOptionInput } from '@vendure/common/lib/generated-types';
+import {
+    CreateGroupOptionInput,
+    CreateProductOptionInput,
+    UpdateProductOptionInput,
+} from '@vendure/common/lib/generated-types';
 import { ID } from '@vendure/common/lib/shared-types';
 import { Connection } from 'typeorm';
 
 import { RequestContext } from '../../api/common/request-context';
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { Translated } from '../../common/types/locale-types';
 import { assertFound } from '../../common/utils';
 import { ProductOptionGroup } from '../../entity/product-option-group/product-option-group.entity';
@@ -27,7 +30,7 @@ export class ProductOptionService {
             .find(ProductOption, {
                 relations: ['group'],
             })
-            .then(options => options.map(option => translateDeep(option, ctx.languageCode)));
+            .then((options) => options.map((option) => translateDeep(option, ctx.languageCode)));
     }
 
     findOne(ctx: RequestContext, id: ID): Promise<Translated<ProductOption> | undefined> {
@@ -35,7 +38,7 @@ export class ProductOptionService {
             .findOne(ProductOption, id, {
                 relations: ['group'],
             })
-            .then(option => option && translateDeep(option, ctx.languageCode));
+            .then((option) => option && translateDeep(option, ctx.languageCode));
     }
 
     async create(
@@ -51,7 +54,7 @@ export class ProductOptionService {
             input,
             entityType: ProductOption,
             translationType: ProductOptionTranslation,
-            beforeSave: po => (po.group = productOptionGroup),
+            beforeSave: (po) => (po.group = productOptionGroup),
         });
         return assertFound(this.findOne(ctx, option.id));
     }

+ 29 - 31
packages/core/src/service/services/product-variant.service.ts

@@ -10,11 +10,10 @@ import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
 import { Connection } from 'typeorm';
 
 import { RequestContext } from '../../api/common/request-context';
-import { DEFAULT_LANGUAGE_CODE } from '../../common/constants';
 import { InternalServerError, UserInputError } from '../../common/error/errors';
 import { ListQueryOptions } from '../../common/types/common-types';
 import { Translated } from '../../common/types/locale-types';
-import { assertFound, idsAreEqual } from '../../common/utils';
+import { idsAreEqual } from '../../common/utils';
 import { ConfigService } from '../../config/config.service';
 import { ProductOptionGroup, ProductVariantPrice, TaxCategory } from '../../entity';
 import { FacetValue } from '../../entity/facet-value/facet-value.entity';
@@ -62,7 +61,7 @@ export class ProductVariantService {
         return this.connection
             .getRepository(ProductVariant)
             .findOne(productVariantId, { relations })
-            .then(result => {
+            .then((result) => {
                 if (result) {
                     return translateDeep(this.applyChannelPriceAndTax(result, ctx), ctx.languageCode);
                 }
@@ -82,8 +81,8 @@ export class ProductVariantService {
                     'featuredAsset',
                 ],
             })
-            .then(variants => {
-                return variants.map(variant =>
+            .then((variants) => {
+                return variants.map((variant) =>
                     translateDeep(this.applyChannelPriceAndTax(variant, ctx), ctx.languageCode, [
                         'options',
                         'facetValues',
@@ -113,8 +112,8 @@ export class ProductVariantService {
                     id: 'ASC',
                 },
             })
-            .then(variants =>
-                variants.map(variant => {
+            .then((variants) =>
+                variants.map((variant) => {
                     const variantWithPrices = this.applyChannelPriceAndTax(variant, ctx);
                     return translateDeep(variantWithPrices, ctx.languageCode, [
                         'options',
@@ -145,7 +144,7 @@ export class ProductVariantService {
         }
 
         return qb.getManyAndCount().then(async ([variants, totalItems]) => {
-            const items = variants.map(variant => {
+            const items = variants.map((variant) => {
                 const variantWithPrices = this.applyChannelPriceAndTax(variant, ctx);
                 return translateDeep(variantWithPrices, ctx.languageCode);
             });
@@ -160,15 +159,17 @@ export class ProductVariantService {
         return this.connection
             .getRepository(ProductVariant)
             .findOne(variantId, { relations: ['options'] })
-            .then(variant => (!variant ? [] : variant.options.map(o => translateDeep(o, ctx.languageCode))));
+            .then((variant) =>
+                !variant ? [] : variant.options.map((o) => translateDeep(o, ctx.languageCode)),
+            );
     }
 
     getFacetValuesForVariant(ctx: RequestContext, variantId: ID): Promise<Array<Translated<FacetValue>>> {
         return this.connection
             .getRepository(ProductVariant)
             .findOne(variantId, { relations: ['facetValues', 'facetValues.facet'] })
-            .then(variant =>
-                !variant ? [] : variant.facetValues.map(o => translateDeep(o, ctx.languageCode, ['facet'])),
+            .then((variant) =>
+                !variant ? [] : variant.facetValues.map((o) => translateDeep(o, ctx.languageCode, ['facet'])),
             );
     }
 
@@ -193,7 +194,10 @@ export class ProductVariantService {
         for (const productInput of input) {
             await this.updateSingle(ctx, productInput);
         }
-        const updatedVariants = await this.findByIds(ctx, input.map(i => i.id));
+        const updatedVariants = await this.findByIds(
+            ctx,
+            input.map((i) => i.id),
+        );
         this.eventBus.publish(new ProductVariantEvent(ctx, updatedVariants, 'updated'));
         return updatedVariants;
     }
@@ -212,7 +216,7 @@ export class ProductVariantService {
             input,
             entityType: ProductVariant,
             translationType: ProductVariantTranslation,
-            beforeSave: async variant => {
+            beforeSave: async (variant) => {
                 const { optionIds } = input;
                 if (optionIds && optionIds.length) {
                     const selectedOptions = await this.connection
@@ -257,7 +261,7 @@ export class ProductVariantService {
             input,
             entityType: ProductVariant,
             translationType: ProductVariantTranslation,
-            beforeSave: async updatedVariant => {
+            beforeSave: async (updatedVariant) => {
                 if (input.taxCategoryId) {
                     const taxCategory = await this.taxCategoryService.findOne(input.taxCategoryId);
                     if (taxCategory) {
@@ -329,7 +333,9 @@ export class ProductVariantService {
      * Populates the `price` field with the price for the specified channel.
      */
     applyChannelPriceAndTax(variant: ProductVariant, ctx: RequestContext): ProductVariant {
-        const channelPrice = variant.productVariantPrices.find(p => idsAreEqual(p.channelId, ctx.channelId));
+        const channelPrice = variant.productVariantPrices.find((p) =>
+            idsAreEqual(p.channelId, ctx.channelId),
+        );
         if (!channelPrice) {
             throw new InternalServerError(`error.no-price-found-for-channel`);
         }
@@ -365,10 +371,15 @@ export class ProductVariantService {
         if (optionIds.length !== product.optionGroups.length) {
             this.throwIncompatibleOptionsError(product.optionGroups);
         }
-        if (!samplesEach(optionIds, product.optionGroups.map(g => g.options.map(o => o.id)))) {
+        if (
+            !samplesEach(
+                optionIds,
+                product.optionGroups.map((g) => g.options.map((o) => o.id)),
+            )
+        ) {
             this.throwIncompatibleOptionsError(product.optionGroups);
         }
-        product.variants.forEach(variant => {
+        product.variants.forEach((variant) => {
             const variantOptionIds = this.sortJoin(variant.options, ',', 'id');
             const inputOptionIds = this.sortJoin(input.optionIds || [], ',');
             if (variantOptionIds === inputOptionIds) {
@@ -387,7 +398,7 @@ export class ProductVariantService {
 
     private sortJoin<T>(arr: T[], glue: string, prop?: keyof T): string {
         return arr
-            .map(x => (prop ? x[prop] : x))
+            .map((x) => (prop ? x[prop] : x))
             .sort()
             .join(glue);
     }
@@ -408,17 +419,4 @@ export class ProductVariantService {
         }
         return taxCategory;
     }
-
-    private createVariantName(productName: string, options: ProductOption[]): string {
-        const optionsSuffix = options
-            .map(option => {
-                const defaultTranslation = option.translations.find(
-                    t => t.languageCode === DEFAULT_LANGUAGE_CODE,
-                );
-                return defaultTranslation ? defaultTranslation.name : option.code;
-            })
-            .join(' ');
-
-        return options.length ? `${productName} ${optionsSuffix}` : productName;
-    }
 }