This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GraphQL: Add layered navigation documentation #5222
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6451cc1
add filtering example
keharper c84fa13
Merge branch 'Q4-integration' of github.com:magento/devdocs into kh_l…
keharper 947dd3f
checkpoint
keharper eab1eb4
checkpoint
keharper dcf8e51
Merge branch 'Q4-integration' of github.com:magento/devdocs into kh_l…
keharper 3de1001
checkpoint
keharper 8a51e3a
Merge branch 'Q4-integration' of github.com:magento/devdocs into kh_l…
keharper 5f22774
checkpoint
keharper 886aa54
checkpoint
keharper 1f661c1
checkpoint
keharper e535435
checkpoint
keharper 8ac3ef8
checkpoint
keharper af580f4
checkpoint
keharper f291b6f
linting errors
keharper 36a0f76
fix link
keharper a292026
Merge branch 'Q4-integration' of github.com:magento/devdocs into kh_l…
keharper e3bca50
update opening sentence
keharper 6e8cd01
remove bogus commit
keharper 056f046
Apply suggestions from code review
keharper ce8f8e4
change code gates
keharper f5125a3
final review comments
keharper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
| group: graphql | ||
| title: Filtering with custom attributes | ||
| --- | ||
|
|
||
| As of Magento 2.3.4, the `filter` attribute of the [`products`]({{page.baseurl}}/graphql/queries/products-234.html) query accepts the `ProductAttributeFilterInput` object. (In previous versions, the `filter` attribute required a `ProductFilterInput` object. This object contained a hard-coded list of filterable attributes, and you could not filter on a custom attribute or any other attribute that was not on the list.) | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| To enable a custom attribute (or any attribute that is not listed by default in the `ProductAttributeFilterInput` object) for filtering, select the attribute on the **Stores** > Attributes > **Product** page in the Admin and edit the following fields: | ||
|
|
||
| Field | Setting | ||
| --- | --- | ||
| **Use in Search** | Yes | ||
| **Visible in Advanced Search** | Yes | ||
| **Use in Layered Navigation** | Filterable (with results) or Filterable (no results) | ||
| **Use in Search Results Layered Navigation** | Yes | ||
|
|
||
| ## Define the filter for your query | ||
|
|
||
| The [`filter`]({{page.baseurl}}/graphql/queries/products-234.html#filter) definition for your custom attribute requires one of the following input data types: | ||
|
|
||
| - `FilterEqualTypeInput` - Specify this data type when the **Catalog Input Type for Store Owner** field for your custom attribute is set to Yes/No, Select, or Multiple select. Your filter can contain the `eq` or `in` attribute. Use the `eq` attribute to exactly match the specified string. Use the `in` attribute to filter on a comma-separated list of values. | ||
| - `FilterMatchTypeInput` - Specify this data type when the the **Catalog Input Type for Store Owner** field for your custom attribute is set to Text Field or Text Area. Your filter must contain the `match` attribute, which will return all items that exactly match the specified string. | ||
| - `FilterRangeTypeInput` - Specify this data type when the the **Catalog Input Type for Store Owner** field for your custom attribute is set to Price or Date. Your filter can contain one or both of the `to` and `from` attributes, which serve to provide a range of values to filter on. | ||
|
|
||
| ## Example | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a great example. Does it make sense to create examples for the other filter types, as well? ( |
||
|
|
||
| In this example, the custom attribute `volume` was assigned to the `bags` attribute group. Running the [`customAttributeMetadata` query]({{page.baseurl}}/graphql/queries/custom-attribute-metadata.html) on this custom attribute reveals that the `label` and `value` values for the attribute's options are as follows: | ||
|
|
||
| `label` | `value` | ||
| --- | --- | ||
| `Large` | `216` | ||
| `Medium` | `217` | ||
| `Small` | `218` | ||
|
|
||
| In this scenario, a `products` search filtered to return items where the `volume` attribute is set to `Large` would be similar to the following: | ||
|
|
||
| **Request** | ||
|
|
||
| ```graphql | ||
| { | ||
| products(filter: { volume: { eq: "216" } }) { | ||
| total_count | ||
| items { | ||
| name | ||
| sku | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| **Response** | ||
|
|
||
| The response might be similar to the following: | ||
|
|
||
| ```json | ||
| { | ||
| "data": { | ||
| "products": { | ||
| "total_count": 1, | ||
| "items": [ | ||
| { | ||
| "name": "Wayfarer Messenger Bag", | ||
| "sku": "24-MB05" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Output attributes | ||
|
|
||
| When a product requires a filter attribute that is not a field on its output schema, inject the attribute name into the class in a module's `di.xml` file. | ||
|
|
||
| ```xml | ||
| <type name="Magento\CatalogGraphQl\Model\Resolver\Products\FilterArgument\ProductEntityAttributesForAst" > | ||
| <arguments> | ||
| <argument name="additionalAttributes" xsi:type="array"> | ||
| <item name="field_to_sort" xsi:type="string">field</item> | ||
| <item name="other_field_to_sort" xsi:type="string">other_field</item> | ||
| </argument> | ||
| </arguments> | ||
| </type> | ||
| ``` | ||
|
|
||
| This example adds `field_to_sort` and `other_field_to_sort` attributes to the `additionalAttributes` array defined in the `ProductEntityAttributesForAst` class. The array already contains the `min_price`, `max_price`, and `category_ids` attributes. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
guides/v2.3/graphql/mutations.md → guides/v2.3/graphql/mutations/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.