@graphcommerce/algolia-products 9.1.0-canary.33 → 9.1.0-canary.35
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @graphcommerce/algolia-products
|
|
2
2
|
|
|
3
|
+
## 9.1.0-canary.35
|
|
4
|
+
|
|
5
|
+
## 9.1.0-canary.34
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [`08f9883`](https://github.com/graphcommerce-org/graphcommerce/commit/08f98833019e726759194a3c1492052f2df052fa) - Correctly detect numeric values from the backend. ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
3
11
|
## 9.1.0-canary.33
|
|
4
12
|
|
|
5
13
|
## 9.1.0-canary.32
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
CategoryResult,
|
|
6
6
|
MeshContext,
|
|
7
7
|
} from '@graphcommerce/graphql-mesh'
|
|
8
|
+
import type { FilterTypes } from '@graphcommerce/magento-product'
|
|
8
9
|
import type { AttributeList } from './getAttributeList'
|
|
9
10
|
import { getIndexName } from './getIndexName'
|
|
10
11
|
import type { GetStoreConfigReturn } from './getStoreConfig'
|
|
@@ -76,6 +77,7 @@ export function algoliaFacetsToAggregations(
|
|
|
76
77
|
algoliaFacets: AlgoliasearchResponse['facets'],
|
|
77
78
|
attributes: AttributeList,
|
|
78
79
|
storeConfig: GetStoreConfigReturn,
|
|
80
|
+
filterTypes: FilterTypes,
|
|
79
81
|
categoryList?: null | CategoryResult,
|
|
80
82
|
groupId?: number,
|
|
81
83
|
): Aggregation[] {
|
|
@@ -96,6 +98,7 @@ export function algoliaFacetsToAggregations(
|
|
|
96
98
|
|
|
97
99
|
const label =
|
|
98
100
|
attributes?.find((attribute) => attribute?.code === attribute_code)?.label ?? attribute_code
|
|
101
|
+
|
|
99
102
|
if (facetIndex === 'categoryIds') {
|
|
100
103
|
aggregations.push({
|
|
101
104
|
label,
|
|
@@ -119,30 +122,25 @@ export function algoliaFacetsToAggregations(
|
|
|
119
122
|
options: algoliaPricesToPricesAggregations(algoliaFacets[facetIndex]),
|
|
120
123
|
position,
|
|
121
124
|
})
|
|
125
|
+
} else if (filterTypes[attribute_code] === 'PRICE') {
|
|
126
|
+
aggregations.push({
|
|
127
|
+
label,
|
|
128
|
+
attribute_code,
|
|
129
|
+
options: algoliaPricesToPricesAggregations(facet),
|
|
130
|
+
position,
|
|
131
|
+
})
|
|
122
132
|
} else {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
aggregations.push({
|
|
135
|
-
label,
|
|
136
|
-
attribute_code,
|
|
137
|
-
options: Object.entries(facet).map(([filter, count]) => ({
|
|
138
|
-
label: filter,
|
|
139
|
-
count,
|
|
140
|
-
// @see productFilterInputToAlgoliafacetFiltersInput for the other side.
|
|
141
|
-
value: filter.replaceAll('/', '_OR_').replaceAll(',', '_AND_'),
|
|
142
|
-
})),
|
|
143
|
-
position,
|
|
144
|
-
})
|
|
145
|
-
}
|
|
133
|
+
aggregations.push({
|
|
134
|
+
label,
|
|
135
|
+
attribute_code,
|
|
136
|
+
options: Object.entries(facet).map(([filter, count]) => ({
|
|
137
|
+
label: filter,
|
|
138
|
+
count,
|
|
139
|
+
// @see productFilterInputToAlgoliafacetFiltersInput for the other side.
|
|
140
|
+
value: filter.replaceAll('/', '_OR_').replaceAll(',', '_AND_'),
|
|
141
|
+
})),
|
|
142
|
+
position,
|
|
143
|
+
})
|
|
146
144
|
}
|
|
147
145
|
})
|
|
148
146
|
|
|
@@ -125,14 +125,14 @@ export type ProductsItemsItem = NonNullable<
|
|
|
125
125
|
* - A string: returns it as-is
|
|
126
126
|
* - Anything else: returns an empty string
|
|
127
127
|
*/
|
|
128
|
-
export function
|
|
128
|
+
export function normalizeValue(value: unknown): string | null {
|
|
129
|
+
if (!value) return null
|
|
129
130
|
if (typeof value === 'string') return value
|
|
130
131
|
if (Array.isArray(value)) {
|
|
131
132
|
const firstNonEmpty = value.find((v) => typeof v === 'string' && v.trim() !== '')
|
|
132
133
|
return typeof firstNonEmpty === 'string' ? firstNonEmpty : ''
|
|
133
134
|
}
|
|
134
|
-
|
|
135
|
-
return ''
|
|
135
|
+
return null
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
/**
|
|
@@ -171,7 +171,7 @@ export function algoliaHitToMagentoProduct(
|
|
|
171
171
|
|
|
172
172
|
// We flatten any custom attribute array values to a string as 95% of the time they are an array
|
|
173
173
|
// because the product is a configurable (which creates an array of values).
|
|
174
|
-
for (const [key, value] of Object.entries(rest)) rest[key] =
|
|
174
|
+
for (const [key, value] of Object.entries(rest)) rest[key] = normalizeValue(value)
|
|
175
175
|
|
|
176
176
|
return {
|
|
177
177
|
staged: false,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AttributeFrontendInputEnum, MeshContext } from '@graphcommerce/graphql-mesh'
|
|
2
|
+
import type { FilterTypes } from '@graphcommerce/magento-product'
|
|
3
|
+
import { filterNonNullableKeys, nonNullable } from '@graphcommerce/next-ui'
|
|
4
|
+
import { Kind, type GraphQLSchema } from 'graphql'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Same as packages/magento-product/components/ProductListItems/getFilterTypes.ts, but usign the
|
|
8
|
+
* mesh.
|
|
9
|
+
*/
|
|
10
|
+
export async function getFilterTypes(context: MeshContext): Promise<FilterTypes> {
|
|
11
|
+
if (import.meta.graphCommerce.magentoVersion >= 247) {
|
|
12
|
+
try {
|
|
13
|
+
const types = await context.m2.Query.attributesList({
|
|
14
|
+
context,
|
|
15
|
+
args: { entityType: 'CATALOG_PRODUCT' },
|
|
16
|
+
selectionSet: '{ items { code frontend_input } }',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
return Object.fromEntries(
|
|
20
|
+
filterNonNullableKeys(types?.items, ['frontend_input'])
|
|
21
|
+
.map((i) => [i.code, i.frontend_input])
|
|
22
|
+
.filter(nonNullable),
|
|
23
|
+
)
|
|
24
|
+
} catch (error) {
|
|
25
|
+
// Fallback to the old way
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const type = (
|
|
30
|
+
context.m2 as typeof context.m2 & { rawSource?: { schema?: GraphQLSchema } }
|
|
31
|
+
)?.rawSource?.schema?.getType('ProductAttributeFilterInput')
|
|
32
|
+
|
|
33
|
+
if (type?.astNode?.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION && type.astNode.fields) {
|
|
34
|
+
const typeMap: FilterTypes = Object.fromEntries(
|
|
35
|
+
type.astNode.fields
|
|
36
|
+
.map<[string, AttributeFrontendInputEnum] | undefined>((field) => {
|
|
37
|
+
if (field.type.kind === Kind.NAMED_TYPE) {
|
|
38
|
+
if (field.type.name.value === 'FilterEqualTypeInput')
|
|
39
|
+
return [field.name.value, 'SELECT']
|
|
40
|
+
if (field.type.name.value === 'FilterRangeTypeInput') return [field.name.value, 'PRICE']
|
|
41
|
+
if (field.type.name.value === 'FilterMatchTypeInput') return [field.name.value, 'TEXT']
|
|
42
|
+
}
|
|
43
|
+
return undefined
|
|
44
|
+
})
|
|
45
|
+
.filter(nonNullable),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
return typeMap
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {}
|
|
52
|
+
}
|
package/mesh/resolvers.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { ProductsItemsItem } from './algoliaHitToMagentoProduct'
|
|
|
6
6
|
import { algoliaHitToMagentoProduct } from './algoliaHitToMagentoProduct'
|
|
7
7
|
import { getAlgoliaSettings } from './getAlgoliaSettings'
|
|
8
8
|
import { getAttributeList } from './getAttributeList'
|
|
9
|
+
import { getFilterTypes } from './getFilterTypes'
|
|
9
10
|
import { getGroupId } from './getGroupId'
|
|
10
11
|
import { getIndexName } from './getIndexName'
|
|
11
12
|
import { getSearchResults } from './getSearchResults'
|
|
@@ -49,6 +50,7 @@ export const resolvers: Resolvers = {
|
|
|
49
50
|
root.algoliaSearchResults?.facets,
|
|
50
51
|
await getAttributeList(context),
|
|
51
52
|
await getStoreConfig(context),
|
|
53
|
+
await getFilterTypes(context),
|
|
52
54
|
await getCategoryList(context),
|
|
53
55
|
getGroupId(context),
|
|
54
56
|
),
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/algolia-products",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.1.0-canary.
|
|
5
|
+
"version": "9.1.0-canary.35",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"generate": "tsx scripts/generate-spec.mts"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@graphcommerce/google-datalayer": "^9.1.0-canary.
|
|
19
|
-
"@graphcommerce/graphql": "^9.1.0-canary.
|
|
20
|
-
"@graphcommerce/graphql-mesh": "^9.1.0-canary.
|
|
21
|
-
"@graphcommerce/magento-customer": "^9.1.0-canary.
|
|
22
|
-
"@graphcommerce/magento-product": "^9.1.0-canary.
|
|
23
|
-
"@graphcommerce/magento-search": "^9.1.0-canary.
|
|
24
|
-
"@graphcommerce/next-config": "^9.1.0-canary.
|
|
25
|
-
"@graphcommerce/next-ui": "^9.1.0-canary.
|
|
18
|
+
"@graphcommerce/google-datalayer": "^9.1.0-canary.35",
|
|
19
|
+
"@graphcommerce/graphql": "^9.1.0-canary.35",
|
|
20
|
+
"@graphcommerce/graphql-mesh": "^9.1.0-canary.35",
|
|
21
|
+
"@graphcommerce/magento-customer": "^9.1.0-canary.35",
|
|
22
|
+
"@graphcommerce/magento-product": "^9.1.0-canary.35",
|
|
23
|
+
"@graphcommerce/magento-search": "^9.1.0-canary.35",
|
|
24
|
+
"@graphcommerce/next-config": "^9.1.0-canary.35",
|
|
25
|
+
"@graphcommerce/next-ui": "^9.1.0-canary.35",
|
|
26
26
|
"react": "^18.2.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|