Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

I need to filter products by productTaxonomyNode id

Solved

I need to filter products by productTaxonomyNode id

AlanDev
Shopify Partner
2 0 0

I need to filter products by productTaxonomyNode id, but I don't found a solution, I have this 

 

    if (filters?.categoryId) {
      _query += `productCategory.productTaxonomyNode.id:gid://shopify/ProductTaxonomyNode/334 `;
    }

    const query = `
      query {
        products(
          ${_query.length > 0 ? `query: "${_query}"` : ''}
          first: ${pageSize}) {
            edges {
                node {
                    id
                    title
                    createdAt
                    description
                    descriptionHtml
                    hasOnlyDefaultVariant
                    hasOutOfStockVariants
                    totalInventory
                    totalVariants
                    tracksInventory
                    featuredImage{
                      url
                    }
                    productCategory{
                      productTaxonomyNode{
                        id
                        name            
                      }
                    }
                    priceRange {
                        minVariantPrice {
                            amount
                            currencyCode
                        }
                    }
                    options{
                      id
                      name
                      position
                      values
                    }
                    variants(first:250){
                      edges{
                        node{
                          availableForSale
                          barcode
                          compareAtPrice
                          price
                          id
                          image{
                            url
                            originalSrc
                            src
                          }
                          inventoryQuantity
                          position
                          sku
                          title
                          weight
                          requiresShipping                        
                        }
                      }
                    }
                }
            }
            pageInfo {
                hasNextPage
                hasPreviousPage
                startCursor
                endCursor
            }
        }
    }    
  `;

 

this code print:

 

      query {
        products(
          query: "productCategory.productTaxonomyNode.id:gid://shopify/ProductTaxonomyNode/334"
          first: 25) {
            edges {
                node {
                    id
                    title
                    createdAt
                    description
                    descriptionHtml
                    hasOnlyDefaultVariant
                    hasOutOfStockVariants
                    totalInventory
                    totalVariants
                    tracksInventory
                    featuredImage{
                      url
                    }
                    productCategory{
                      productTaxonomyNode{
                        id
                        name            
                      }
                    }
                    priceRange {
                        minVariantPrice {
                            amount
                            currencyCode
                        }
                    }
                    options{
                      id
                      name
                      position
                      values
                    }
                    variants(first:250){
                      edges{
                        node{
                          availableForSale
                          barcode
                          compareAtPrice
                          price
                          id
                          image{
                            url
                            originalSrc
                            src
                          }
                          inventoryQuantity
                          position
                          sku
                          title
                          weight
                          requiresShipping                        
                        }
                      }
                    }
                }
            }
            pageInfo {
                hasNextPage
                hasPreviousPage
                startCursor
                endCursor
            }
        }
    }  

 

but I don't have the products filtered by the  productTaxonomyNode id, what I can do?

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 239 535

This is an accepted solution.

Hey @AlanDev

 

Thanks for sharing that example. Currently, the category or taxonomy node is not an available filter parameter for products queries. 

 

You can see a list of available queries you can use here: https://shopify.dev/docs/api/admin-graphql/2024-01/queries/products#argument-query 

 

As a workaround, you could tag the products with their taxonomy so you can query them through a filter. Alternatively, query all of the products and then once that is returned, filter out the ones that have the proper taxonomy that you're looking for. 

 

Hope that helps, 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

ShopifyDevSup
Shopify Staff
1453 239 535

This is an accepted solution.

Hey @AlanDev

 

Thanks for sharing that example. Currently, the category or taxonomy node is not an available filter parameter for products queries. 

 

You can see a list of available queries you can use here: https://shopify.dev/docs/api/admin-graphql/2024-01/queries/products#argument-query 

 

As a workaround, you could tag the products with their taxonomy so you can query them through a filter. Alternatively, query all of the products and then once that is returned, filter out the ones that have the proper taxonomy that you're looking for. 

 

Hope that helps, 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

AlanDev
Shopify Partner
2 0 0

Thank you for reply to me!, maybe in the future, will be great an update with that as filter.