@reactionary/medusa 0.9.23 → 0.9.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,7 +44,7 @@ class MedusaProductSearchCapability extends ProductSearchCapability {
44
44
  break;
45
45
  }
46
46
  candidate = categoryResult.product_categories.find(
47
- (cat) => cat.metadata?.["external_id"] === externalId
47
+ (cat) => cat.external_id === externalId
48
48
  );
49
49
  if (candidate) {
50
50
  break;
@@ -59,11 +59,11 @@ class MedusaProductSearchCapability extends ProductSearchCapability {
59
59
  }
60
60
  return candidate || null;
61
61
  }
62
- queryByTermPayload(payload, categoryIdToFind) {
62
+ queryByTermPayload(payload, categoryIdsToFind) {
63
63
  const finalSearch = (payload.search.term || "").trim().replace("*", "");
64
64
  return {
65
65
  q: finalSearch,
66
- ...categoryIdToFind ? { category_id: categoryIdToFind } : {},
66
+ ...categoryIdsToFind?.length ? { category_id: categoryIdsToFind } : {},
67
67
  limit: payload.search.paginationOptions.pageSize,
68
68
  fields: "+metadata.*,+external_id",
69
69
  offset: (payload.search.paginationOptions.pageNumber - 1) * payload.search.paginationOptions.pageSize
@@ -79,9 +79,21 @@ class MedusaProductSearchCapability extends ProductSearchCapability {
79
79
  });
80
80
  return success(facetValueIdentifier);
81
81
  }
82
+ async getAllChildCategoryIds(id) {
83
+ const client = await this.medusaApi.getClient();
84
+ const { product_category } = await client.store.category.retrieve(id, {
85
+ include_descendants_tree: true,
86
+ fields: "*category_children"
87
+ });
88
+ const flatten = (category) => [
89
+ category.id,
90
+ ...(category.category_children ?? []).flatMap(flatten)
91
+ ];
92
+ return flatten(product_category);
93
+ }
82
94
  async queryByTerm(payload) {
83
95
  const client = await this.medusaApi.getClient();
84
- let categoryIdToFind = null;
96
+ let categoryIdsToFind = null;
85
97
  if (payload.search.categoryFilter?.key) {
86
98
  debug(
87
99
  `Resolving category filter for key: ${payload.search.categoryFilter.key}`
@@ -90,9 +102,11 @@ class MedusaProductSearchCapability extends ProductSearchCapability {
90
102
  payload.search.categoryFilter.key
91
103
  );
92
104
  if (category) {
93
- categoryIdToFind = category.id;
105
+ categoryIdsToFind = await this.getAllChildCategoryIds(
106
+ category.id
107
+ );
94
108
  debug(
95
- `Resolved category filter key ${payload.search.categoryFilter.key} to id: ${categoryIdToFind}`
109
+ `Resolved category filter key ${payload.search.categoryFilter.key} to id: ${categoryIdsToFind}`
96
110
  );
97
111
  } else {
98
112
  debug(
@@ -100,7 +114,9 @@ class MedusaProductSearchCapability extends ProductSearchCapability {
100
114
  );
101
115
  }
102
116
  }
103
- const response = await client.store.product.list(this.queryByTermPayload(payload, categoryIdToFind));
117
+ const response = await client.store.product.list(
118
+ this.queryByTermPayload(payload, categoryIdsToFind)
119
+ );
104
120
  const result = this.factory.parseSearchResult(this.context, response, payload);
105
121
  if (debug.enabled) {
106
122
  debug(
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@reactionary/medusa",
3
- "version": "0.9.23",
3
+ "version": "0.9.25",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
8
  "@medusajs/js-sdk": "^2.13.3",
9
- "@reactionary/core": "0.9.23",
9
+ "@reactionary/core": "0.9.25",
10
10
  "debug": "^4.4.3",
11
11
  "@medusajs/types": "^2.13.3",
12
12
  "zod": "4.1.9"
@@ -9,7 +9,8 @@ export declare class MedusaProductSearchCapability<TFactory extends ProductSearc
9
9
  protected factory: ProductSearchFactoryWithOutput<TFactory>;
10
10
  constructor(config: MedusaConfiguration, cache: Cache, context: RequestContext, medusaApi: MedusaAPI, factory: ProductSearchFactoryWithOutput<TFactory>);
11
11
  protected resolveCategoryIdByExternalId(externalId: string): Promise<StoreProductCategory | null>;
12
- protected queryByTermPayload(payload: ProductSearchQueryByTerm, categoryIdToFind: string | null): any;
12
+ protected queryByTermPayload(payload: ProductSearchQueryByTerm, categoryIdsToFind: string[] | null): any;
13
13
  createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<Result<FacetValueIdentifier>>;
14
+ protected getAllChildCategoryIds(id: string): Promise<string[]>;
14
15
  queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<ProductSearchFactoryOutput<TFactory>>>;
15
16
  }