Skip to content

Commit

Permalink
fix(core): Return all assets when querying product by slug
Browse files Browse the repository at this point in the history
Fixes #820
  • Loading branch information
michaelbromley committed Apr 13, 2021
1 parent 317a63c commit acb3fb0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/core/e2e/product.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,33 @@ describe('Product resolver', () => {
expect(product.slug).toBe('curvy-monitor');
});

// https://github.com/vendure-ecommerce/vendure/issues/820
it('by slug with multiple assets', async () => {
const { product: product1 } = await adminClient.query<
GetProductSimple.Query,
GetProductSimple.Variables
>(GET_PRODUCT_SIMPLE, { id: 'T_1' });
const result = await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(
UPDATE_PRODUCT,
{
input: {
id: product1!.id,
assetIds: ['T_1', 'T_2', 'T_3'],
},
},
);
const { product } = await adminClient.query<
GetProductWithVariants.Query,
GetProductWithVariants.Variables
>(GET_PRODUCT_WITH_VARIANTS, { slug: product1!.slug });

if (!product) {
fail('Product not found');
return;
}
expect(product.assets.map(a => a.id)).toEqual(['T_1', 'T_2', 'T_3']);
});

// https://github.com/vendure-ecommerce/vendure/issues/538
it('falls back to default language slug', async () => {
const { product } = await adminClient.query<GetProductSimple.Query, GetProductSimple.Variables>(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/service/services/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ export class ProductService {
.andWhere('product.deletedAt IS NULL')
.andWhere('channel.id = :channelId', { channelId: ctx.channelId })
.addSelect(
// tslint:disable-next-line:max-line-length
`CASE product_translations.languageCode WHEN '${ctx.languageCode}' THEN 2 WHEN '${ctx.channel.defaultLanguageCode}' THEN 1 ELSE 0 END`,
'sort_order',
)
.orderBy('sort_order', 'DESC')
.limit(1)
.getOne()
.then(product =>
product
Expand Down

0 comments on commit acb3fb0

Please sign in to comment.