Riqwan - thanks for your efforts, its highly appreciated 🙏.
I actually extended the product-category service like this to retrieve category ancestors:
class ProductCategoryService extends MedusaProductCategoryService {
/**
* Retrieves a product category by id.
* @param productCategoryId - the id of the product category to retrieve.
* @param config - the config of the product category to retrieve.
* @return the product category.
*/
async retrieveByHandle(
handle: string,
config: FindConfig<ProductCategory> = {},
selector: Selector<ProductCategory> = {}
): Promise<ProductCategory> {
if (!isDefined(handle)) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`"handle" must be defined`
);
}
const selectors = Object.assign({ handle: handle }, selector);
const query = buildQuery(selectors, config);
const productCategoryRepo = this.activeManager_.withRepository(
this.productCategoryRepo_
);
const productCategoryWithDescendants = await productCategoryRepo.findOne(
query
);
const productCategoryWithParents =
await productCategoryRepo.findAncestorsTree(
productCategoryWithDescendants
);
if (!productCategoryWithDescendants) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Handle: ${handle} was not found`
);
}
return productCategoryWithParents;
}
This is the first route I built