Skip to content

Commit 552c876

Browse files
author
jefffischer
committed
Merge pull request BroadleafCommerce#75 from BroadleafCommerce/qa-989-defaultCategory-filtering
Parent Category filter on Product list not working properly
2 parents 9487e6d + bf2a4e5 commit 552c876

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

admin/broadleaf-admin-module/src/main/java/org/broadleafcommerce/admin/server/service/handler/ProductCustomPersistenceHandler.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,21 @@ public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTra
151151
List<String> filterValues = fsc.getFilterValues();
152152
cto.getCriteriaMap().remove("defaultCategory");
153153
FilterMapping filterMapping = new FilterMapping()
154-
.withFieldPath(new FieldPath().withTargetProperty("allParentCategoryXrefs.category.id"))
154+
.withFieldPath(new FieldPath().withTargetProperty("allParentCategoryXrefs.id"))
155155
.withDirectFilterValues(filterValues)
156156
.withRestriction(new Restriction()
157157
.withPredicateProvider(new PredicateProvider() {
158158
@Override
159159
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder,
160160
From root, String ceilingEntity,
161161
String fullPropertyName, Path explicitPath, List directValues) {
162-
163-
//the property to be matched against (allParentCategoryXrefs.category.id) comes as "explicitPath"
164-
//the specifics of what values are acceptable (those given as filter values, that in addition are defaults)
165-
//are resolved in a sub-query
162+
//We want to limit the product we find to those who have a CategoryProductXref that
163+
//is unarchived, is the defaultReference, and is the selected filter category. We
164+
//do this in a subquery to avoid an additional join that would cause duplicate query
165+
//results.
166166
Subquery<Long> sub = fieldPathBuilder.getCriteria().subquery(Long.class);
167167
Root<CategoryProductXrefImpl> subRoot = sub.from(CategoryProductXrefImpl.class);
168-
sub.select(subRoot.get("category").get("id").as(Long.class));
168+
sub.select(subRoot.get("id").as(Long.class));
169169
List<Predicate> subRestrictions = new ArrayList<Predicate>();
170170
subRestrictions.add(builder.equal(subRoot.get("defaultReference"), Boolean.TRUE));
171171
subRestrictions.add(subRoot.get("category").get("id").in(directValues));

0 commit comments

Comments
 (0)