0

I have to filter the Magento 2 GraphQL query to filter based on the product type.

products(
            filter: {category_id: {eq: "3"}},
            sort: {name: ASC},
            pageSize: 2,
            currentPage: 1
        ) {
            total_count
            items {
                __typename
                name
                sku
                description {
                    html
                }
                short_description {
                    html
                }
                image {
                    url
                    label
                    position
                    disabled
                }
                small_image {
                    url
                    label
                    position
                    disabled
                }
                thumbnail {
                    url
                    label
                    position
                    disabled
                }
                price_range {
                    minimum_price {
                        regular_price {
                            value
                            currency
                        }
                        final_price {
                            value
                            currency
                        }
                        discount {
                            amount_off
                            percent_off
                        }
                    }
                    maximum_price {
                        regular_price {
                            value
                            currency
                        }
                        final_price {
                            value
                            currency
                        }
                        discount {
                            amount_off
                            percent_off
                        }
                    }
                }
            }
        }

In this query I am filtering using the category but I want it to filter the product by type. eg - I only want to fetch the downloadable products.

Thanks in advance.

2 Answers 2

0

To filter a GraphQL product query by product type in Magento 2, you can use the filter argument with the ProductFilterInput input type. Here's an example query:

query {
  products(filter: {type_id: {eq: "simple"}}) {
    items {
      id
      sku
      name
      price {
        regularPrice {
          value
          currency
        }
      }
    }
  }
}

In this query, we're using the products query to retrieve a list of products. The filter argument is used to filter the results based on certain criteria, in this case, the type_id field is filtered by the value "simple".

You can replace "simple" with the product type that you want to filter by, such as "configurable", "virtual", "bundle", etc.

1
  • "Field \"type_id\" is not defined by type ProductAttributeFilterInput." I am getting this error Mar 9, 2023 at 7:38
0

Yes, did not work for me as well, type_id is not defined. @Deepak did you find any solution for this ?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.