cancel
Showing results for 
Search instead for 
Did you mean: 

GraphQL sorting and filtering to use the highest price of product variants instead of lowest

GraphQL sorting and filtering to use the highest price of product variants instead of lowest

 

I'm working with Graphql in my application, specifically with product filtering and sorting. Currently, the system is configured to use the lowest price of the product variants for filtering and sorting purposes. However, I need to modify this behavior to utilize the highest price of the product variants instead. Additionally, I would like the highest price to be reflected in the aggregations as well. Currently, the aggregations show the lowest price, but I need them to display the highest price of the product variants. Could someone please guide me on how to make these changes in my GraphQL configuration? I would greatly appreciate any insights, examples, or suggestions on how to achieve this.

2 REPLIES 2

Re: GraphQL sorting and filtering to use the highest price of product variants instead of lowest

To modify your GraphQL configuration to use the highest price of product variants for filtering, sorting, and aggregations, follow the procedure given below:

1. Update the GraphQL schema to include a new field 'highestPrice' in the 'Product' type representing the highest price among all variants.

 

2. Modify the resolver functions to calculate and provide the highest price for each product based on its variants.

 

3. Adjust aggregation queries in your backend to display the highest price in the aggregations.

 

4. Update client-side GraphQL queries to request the new 'highestPrice' field instead of the previous lowest price field.

Found the above suggestion helpful, hit the "Kudos" & Accept" as the Solution!

Re: GraphQL sorting and filtering to use the highest price of product variants instead of lowest

by this I can get the highest price of the variants only. This won't change in aggregations and if i search with that price product won't be available.

eg:-  "data": {
"products": {
"total_count": 35,
"aggregations": [
{
"attribute_code": "price",
"label": "Price",
"options": [
{
"label": "0-1000",
"value": "0_1000",
"count": 27,
"__typename": "AggregationOption"
},
{
"label": "1000-2000",
"value": "1000_2000",
"count": 6,
"__typename": "AggregationOption"
},
{
"label": "2000-3000",
"value": "2000_3000",
"count": 1,
"__typename": "AggregationOption"
},
{
"label": "6000-7000",
"value": "6000_7000",
"count": 1,
"__typename": "AggregationOption"
}
],

 

in this aggregation you can see last one is 6000-7000 but i have a varient in config product which has a price of 15000   i need to add 15000 in the price aggrigation 

 

Magento defaultly takes the lowest price among the variant i need to change this logic and to take the highest priced variant