diff --git a/packages/core/e2e/custom-fields.e2e-spec.ts b/packages/core/e2e/custom-fields.e2e-spec.ts index 2d4e577611..c2fbea711e 100644 --- a/packages/core/e2e/custom-fields.e2e-spec.ts +++ b/packages/core/e2e/custom-fields.e2e-spec.ts @@ -470,7 +470,7 @@ describe('Custom fields', () => { } } `); - }, 'The custom field "stringWithOptions" value ["tiny"] is invalid. Valid options are [\'small\', \'medium\', \'large\']'), + }, "The custom field \"stringWithOptions\" value [\"tiny\"] is invalid. Valid options are ['small', 'medium', 'large']"), ); it('valid string option', async () => { @@ -951,6 +951,36 @@ describe('Custom fields', () => { ); }); + describe('product on productVariant entity', () => { + it('is translated', async () => { + const { productVariants } = await adminClient.query(gql` + query { + productVariants(productId: "T_1") { + items { + product { + name + id + customFields { + localeStringWithDefault + stringWithDefault + } + } + } + } + } + `); + + expect(productVariants.items[0].product).toEqual({ + id: 'T_1', + name: 'Laptop', + customFields: { + localeStringWithDefault: 'hola', + stringWithDefault: 'hello', + }, + }); + }); + }); + describe('unique constraint', () => { it('setting unique value works', async () => { const result = await adminClient.query( diff --git a/packages/core/src/api/resolvers/entity/product-variant-entity.resolver.ts b/packages/core/src/api/resolvers/entity/product-variant-entity.resolver.ts index b79d095556..2f12f487b3 100644 --- a/packages/core/src/api/resolvers/entity/product-variant-entity.resolver.ts +++ b/packages/core/src/api/resolvers/entity/product-variant-entity.resolver.ts @@ -79,9 +79,10 @@ export class ProductVariantEntityResolver { @Ctx() ctx: RequestContext, @Parent() productVariant: ProductVariant, ): Promise { - if (productVariant.product) { + if (productVariant.product.name) { return productVariant.product; } + return this.requestContextCache.get( ctx, `ProductVariantEntityResolver.product(${productVariant.productId})`, diff --git a/packages/core/src/service/services/product-variant.service.ts b/packages/core/src/service/services/product-variant.service.ts index 34a0efe1ba..61ebf3d891 100644 --- a/packages/core/src/service/services/product-variant.service.ts +++ b/packages/core/src/service/services/product-variant.service.ts @@ -291,9 +291,16 @@ export class ProductVariantService { * page, this method returns only the Product itself. */ async getProductForVariant(ctx: RequestContext, variant: ProductVariant): Promise> { - const product = await this.connection.getEntityOrThrow(ctx, Product, variant.productId, { - includeSoftDeleted: true, - }); + let product; + + if (!variant.product) { + product = await this.connection.getEntityOrThrow(ctx, Product, variant.productId, { + includeSoftDeleted: true, + }); + } else { + product = variant.product; + } + return this.translator.translate(product, ctx); }