diff --git a/.changeset/cuddly-kiwis-roll.md b/.changeset/cuddly-kiwis-roll.md new file mode 100644 index 0000000000..6f0db6c86c --- /dev/null +++ b/.changeset/cuddly-kiwis-roll.md @@ -0,0 +1,5 @@ +--- +"@medusajs/product": patch +--- + +fix(product): Correctly fetch category descendants by handle \ No newline at end of file diff --git a/integration-tests/http/__tests__/product-category/admin/product-category.spec.ts b/integration-tests/http/__tests__/product-category/admin/product-category.spec.ts index 8dd486f063..93a5dbfc75 100644 --- a/integration-tests/http/__tests__/product-category/admin/product-category.spec.ts +++ b/integration-tests/http/__tests__/product-category/admin/product-category.spec.ts @@ -598,6 +598,33 @@ medusaIntegrationTestRunner({ ) }) + it("should filter by handle and retrieve descendants tree", async () => { + const response = await api.get( + `/admin/product-categories?handle=${productCategoryParent.handle}&include_descendants_tree=true`, + adminHeaders + ) + + expect(response.status).toEqual(200) + expect(response.data.product_categories).toEqual([ + expect.objectContaining({ + id: productCategoryParent.id, + handle: productCategoryParent.handle, + category_children: [ + expect.objectContaining({ + id: productCategory.id, + handle: productCategory.handle, + category_children: [ + expect.objectContaining({ + id: productCategoryChild.id, + handle: productCategoryChild.handle, + }), + ], + }), + ], + }), + ]) + }) + it("filters based on free text on name and handle columns", async () => { const response = await api.get( `/admin/product-categories?q=men&limit=1`, diff --git a/packages/modules/product/src/repositories/product-category.ts b/packages/modules/product/src/repositories/product-category.ts index c5ce205272..1e62a7dde1 100644 --- a/packages/modules/product/src/repositories/product-category.ts +++ b/packages/modules/product/src/repositories/product-category.ts @@ -182,6 +182,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito } as MikroOptions delete where.id + delete where.handle delete where.mpath delete where.parent_category_id