@reactionary/provider-commercetools 0.1.8 → 0.1.10

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.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@reactionary/provider-commercetools",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.1.8",
7
+ "@reactionary/core": "0.1.10",
8
8
  "debug": "^4.4.3",
9
9
  "zod": "4.1.9",
10
10
  "@commercetools/ts-client": "^4.2.1",
@@ -40,11 +40,10 @@ class CommercetoolsSearchProvider extends ProductSearchProvider {
40
40
  }
41
41
  async getFacetQuery(payload, selectedFacetValue) {
42
42
  if (selectedFacetValue.facet.key === "categories") {
43
- const category = await this.resolveCategoryFromKey({ key: selectedFacetValue.key });
44
43
  return {
45
44
  exact: {
46
45
  field: "categoriesSubTree",
47
- values: [category.id],
46
+ values: [selectedFacetValue.key],
48
47
  fieldType: "text"
49
48
  }
50
49
  };
@@ -101,12 +100,11 @@ class CommercetoolsSearchProvider extends ProductSearchProvider {
101
100
  if (!payload.search.categoryFilter) {
102
101
  return void 0;
103
102
  }
104
- const category = await this.resolveCategoryFromKey({ key: payload.search.categoryFilter.key });
105
- if (category) {
103
+ if (payload.search.categoryFilter.key) {
106
104
  return {
107
105
  exact: {
108
106
  field: "categoriesSubTree",
109
- values: [category.id],
107
+ values: [payload.search.categoryFilter.key],
110
108
  fieldType: "text"
111
109
  }
112
110
  };
@@ -178,12 +176,14 @@ class CommercetoolsSearchProvider extends ProductSearchProvider {
178
176
  async createCategoryNavigationFilter(payload) {
179
177
  const categoryPath = payload.categoryPath;
180
178
  const deepestCategory = categoryPath[categoryPath.length - 1];
179
+ const resolvedCategory = await this.resolveCategoryFromKey({ key: deepestCategory.identifier.key });
180
+ const resolvedId = resolvedCategory?.id;
181
181
  const facetIdentifier = {
182
182
  key: "categories"
183
183
  };
184
184
  const facetValueIdentifier = {
185
185
  facet: facetIdentifier,
186
- key: deepestCategory.identifier.key
186
+ key: resolvedId || "unknown"
187
187
  };
188
188
  return facetValueIdentifier;
189
189
  }
@@ -255,10 +255,14 @@ class CommercetoolsSearchProvider extends ProductSearchProvider {
255
255
  if (!categoryFacet) {
256
256
  return;
257
257
  }
258
+ const resolvedCategories = categoryFacet.values.map((facetValue) => this.resolveCategoryFromId({ id: facetValue.identifier.key }));
259
+ const categories = await Promise.all(resolvedCategories);
258
260
  for (const facetValue of categoryFacet.values) {
259
261
  try {
260
- const category = await this.resolveCategoryFromId({ id: facetValue.identifier.key });
261
- facetValue.identifier.key = category.key || category.id;
262
+ const category = categories.find((c) => c.id === facetValue.identifier.key);
263
+ if (!category) {
264
+ continue;
265
+ }
262
266
  facetValue.name = category.name[this.context.languageContext.locale] || category.id;
263
267
  } catch (error) {
264
268
  if (debug.enabled) {