how to set/pass price sorting parameter in graphql.json for prouducts query without collection

dvyadav
Shopify Partner
7 1 1


<?php

$query = <<<'JSON'
query ($first: Int, $sortKey:ProductSortKeys, $reverse:Boolean, $title: String)
{ products(first: $first,sortKey:$sortKey, reverse:$reverse, query: $title) {
edges {
node {
id,
title,
handle,
image:featuredImage{src:originalSrc},
price:priceRangeV2{min:minVariantPrice{amount}, max:maxVariantPrice{amount}}
}
}
}
}
JSON;
$variables["first"] = 50;
if(!empty($sortKey)){
$variables["sortKey"]=$sortKey;
$variables["reverse"] = $sortKeyReverse;
}
if(!empty($searchTerm)){
$variables["title"] = "'$searchTerm' AND price:>=$minPrice AND price:<$maxPrice ";
}else{
$variables["title"] = " price:>=$minPrice AND price:<=$maxPrice ";
}
$jsonQuery = json_encode(['query' => $query, 'variables' => $variables]);
$products = shopifyGraphqlCall($shopAccessToken,$storeUrlName,$jsonQuery);
echo $products;
?>

These fields "TITLE","PRODUCT_TYPE","VENDOR","INVENTORY_TOTAL","UPDATED_AT","CREATED_AT","PUBLISHED_AT", "ID", "RELEVANCE".

we can pass in sortKey parameter but we want sorting according price ascending/descending and best selling ascending/descending order

 

 

0 Likes