Jelajahi Sumber

fix(core): Handle empty state for product and variant id filter (#3064)

David Höck 1 tahun lalu
induk
melakukan
9a03c84b73

+ 14 - 6
packages/core/src/config/catalog/default-collection-filters.ts

@@ -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);
         }
     },
@@ -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);
         }
     },