Skip to content

Commit

Permalink
fix(core): Handle empty state for product and variant id filter (#3064)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlhck authored Sep 13, 2024
1 parent ee87431 commit 9a03c84
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/core/src/config/catalog/default-collection-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,19 @@ export const variantIdCollectionFilter = new CollectionFilter({
code: 'variant-id-filter',
description: [{ languageCode: LanguageCode.en, value: 'Manually select product variants' }],
apply: (qb, args) => {
if (args.variantIds.length === 0) {
return qb;
}
const emptyIds = args.variantIds.length === 0;
const variantIdsKey = randomSuffix('variantIds');
const clause = `productVariant.id IN (:...${variantIdsKey})`;
const params = { [variantIdsKey]: args.variantIds };
if (args.combineWithAnd === false) {
if (emptyIds) {
return qb;
}
return qb.orWhere(clause, params);
} else {
if (emptyIds) {
return qb.andWhere('1 = 0');
}
return qb.andWhere(clause, params);
}
},
Expand All @@ -242,15 +246,19 @@ export const productIdCollectionFilter = new CollectionFilter({
code: 'product-id-filter',
description: [{ languageCode: LanguageCode.en, value: 'Manually select products' }],
apply: (qb, args) => {
if (args.productIds.length === 0) {
return qb;
}
const emptyIds = args.productIds.length === 0;
const productIdsKey = randomSuffix('productIds');
const clause = `productVariant.productId IN (:...${productIdsKey})`;
const params = { [productIdsKey]: args.productIds };
if (args.combineWithAnd === false) {
if (emptyIds) {
return qb;
}
return qb.orWhere(clause, params);
} else {
if (emptyIds) {
return qb.andWhere('1 = 0');
}
return qb.andWhere(clause, params);
}
},
Expand Down

0 comments on commit 9a03c84

Please sign in to comment.