You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: src/guides/v2.3/graphql/queries/products.md
+74Lines changed: 74 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,6 +133,8 @@ Attribute | Data type | Description
133
133
{:.bs-callout-info}
134
134
If you use MySQL for searches and you specify `relevance` and another sorting attribute, the `relevance` results are always listed first. This limitation does not apply to [Elasticsearch]({{page.baseurl}}/config-guide/elasticsearch/configure-magento.html).
135
135
136
+
To enable sorting by an attribute that is not in the `ProductAttributeSortInput` object, set the **Stores** > Attributes > **Product** > <AttributeName> > **Storefront Properties** > **Use in Search** and **Used in Sorting in Product Listing** fields to Yes.
137
+
136
138
## Deprecated input attributes
137
139
138
140
The `filter` and `sort` attributes require new input objects. The following sections list the deprecated attributes.
@@ -1021,6 +1023,78 @@ In the following example, a catalog price rule that provides a 10% discount on a
1021
1023
}
1022
1024
```
1023
1025
1026
+
### Sort by a custom attribute
1027
+
1028
+
In this example, the `description` attribute has been enabled by setting the **Stores** > Attributes > **Product** > description > **Storefront Properties** > **Use in Search** and **Used in Sorting in Product Listing** fields to Yes. The query returns all products with a price range of $28 to $30, sorted by the description.
1029
+
1030
+
**Request:**
1031
+
1032
+
```graphql
1033
+
{
1034
+
products(filter: { price: { from: "28"to: "30"} }
1035
+
sort: {
1036
+
description: ASC
1037
+
}) {
1038
+
total_count
1039
+
items {
1040
+
name
1041
+
sku
1042
+
description {
1043
+
html
1044
+
}
1045
+
price_range {
1046
+
maximum_price {
1047
+
regular_price {
1048
+
value
1049
+
}
1050
+
}
1051
+
}
1052
+
}
1053
+
}
1054
+
}
1055
+
```
1056
+
1057
+
**Response:**
1058
+
1059
+
```json
1060
+
{
1061
+
"data": {
1062
+
"products": {
1063
+
"total_count": 25,
1064
+
"items": [
1065
+
{
1066
+
"name": "Erikssen CoolTech™ Fitness Tank",
1067
+
"sku": "MT01",
1068
+
"description": {
1069
+
"html": "<p>A good running tank helps make the miles pass by keep you cool. The Erikssen CoolTech™ Fitness Tank completes that mission, with performance fabric engineered to wick perspiration and promote airflow.</p>\n<p>• Red performance tank.<br />• Slight scoop neckline. <br />• Reflectivity. <br />• Machine wash/dry.</p>"
1070
+
},
1071
+
"price_range": {
1072
+
"maximum_price": {
1073
+
"regular_price": {
1074
+
"value": 29
1075
+
}
1076
+
}
1077
+
}
1078
+
},
1079
+
{
1080
+
"name": "Primo Endurance Tank",
1081
+
"sku": "MT03",
1082
+
"description": {
1083
+
"html": "<p>Chances are your workout goes beyond free weights, which is why the Primo Endurance Tank employs maximum versatility. Run, lift or play ball – this breathable mesh top will keep you cool during all your activities.</p>\n<p>• Red heather tank with gray pocket.<br />• Chafe-resistant flatlock seams. <br />• Relaxed fit. <br />• Contrast topstitching.<br />• Machine wash/dry.</p>"
1084
+
},
1085
+
"price_range": {
1086
+
"maximum_price": {
1087
+
"regular_price": {
1088
+
"value": 29
1089
+
}
1090
+
}
1091
+
}
1092
+
},
1093
+
...
1094
+
}
1095
+
}
1096
+
}
1097
+
```
1024
1098
### Retrieve related products, up-sells, and cross-sells
1025
1099
1026
1100
The following query shows how to get related products, up-sells, and cross-sells for a product:
0 commit comments