how use logical operator with metafield and object productFilter

max8392
Shopify Partner
2 0 0

Good morning,

I would like to use hydrogen to create custom filters. I would like to use logical operators such as "<, >, =".

 

I have metafields to manage dimensions.

 

For example, I have a "largeur" metafield of type "String".

I managed to add a filter to my local hydrogen site.
If I filter on the "largeur" at "40", I see the products with a "largeur" of "40".

 

The filter adds the property in my url
http://localhost:3000/collections/brides?largeur=40

 

React

//I retrieve the property and create a productMetafield to add it to my ProductFilter object
if(largeur){
productMetafield = {key: 'largeur', namespace: 'custom', value: largeur}
}

const {collection} = await storefront.query(COLLECTION_QUERY, {
variables: {handle, ...paginationVariables,
productFilter: { price, productMetafield },
},
});

 

Graphql

queryCollection(
$handle: String!
...
$productPriceFilter: [ProductFilter!]
) @inContext(country: $country, language: $language) {
collection(handle: $handle) {
...
products(
...
filters: $productPriceFilter
) {
nodes {
...ProductItem
}

 

I would like to retrieve products from 0 to 40 in "largeur". Could you help me ?

 

THANKS

 
Replies 0 (0)