Skip to content

Commit a501364

Browse files
authored
fix(product): Correctly fetch category descendants by handle (medusajs#13579)
This PR fixes the issue medusajs#13518 where product category descendants were not retrieved when filtering by handle with the include_descendants_tree flag. The handle filter was not being correctly removed before the descendant tree query was executed.
1 parent 513b352 commit a501364

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

.changeset/cuddly-kiwis-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/product": patch
3+
---
4+
5+
fix(product): Correctly fetch category descendants by handle

integration-tests/http/__tests__/product-category/admin/product-category.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,33 @@ medusaIntegrationTestRunner({
598598
)
599599
})
600600

601+
it("should filter by handle and retrieve descendants tree", async () => {
602+
const response = await api.get(
603+
`/admin/product-categories?handle=${productCategoryParent.handle}&include_descendants_tree=true`,
604+
adminHeaders
605+
)
606+
607+
expect(response.status).toEqual(200)
608+
expect(response.data.product_categories).toEqual([
609+
expect.objectContaining({
610+
id: productCategoryParent.id,
611+
handle: productCategoryParent.handle,
612+
category_children: [
613+
expect.objectContaining({
614+
id: productCategory.id,
615+
handle: productCategory.handle,
616+
category_children: [
617+
expect.objectContaining({
618+
id: productCategoryChild.id,
619+
handle: productCategoryChild.handle,
620+
}),
621+
],
622+
}),
623+
],
624+
}),
625+
])
626+
})
627+
601628
it("filters based on free text on name and handle columns", async () => {
602629
const response = await api.get(
603630
`/admin/product-categories?q=men&limit=1`,

packages/modules/product/src/repositories/product-category.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
182182
} as MikroOptions<any>
183183

184184
delete where.id
185+
delete where.handle
185186
delete where.mpath
186187
delete where.parent_category_id
187188

0 commit comments

Comments
 (0)