【问题标题】:Shopify Storefront GraphQL filtering products within a collectionShopify Storefront GraphQL 过滤集合中的产品
【发布时间】:2022-01-12 01:18:17
【问题描述】:

根据本文档: https://shopify.dev/custom-storefronts/products/filter-products#query-products-by-type

我们应该能够使用collectionByHandle 过滤集合中的产品。

我在 Shopify GraphiQL 应用程序浏览器工具中创建了一个非常基本的测试查询。当我运行记录的查询时,它返回所有产品,根本不过滤。见下文:

这看起来像是 API 的错误,对吧?还是我缺少一些基本的东西?

【问题讨论】:

    标签: graphql shopify shopify-storefront-api


    【解决方案1】:

    好的,这原来是一个配置问题。要允许按产品类型进行过滤,需要在您商店的管理员中打开它。如果您导航到: 在线商店 > 导航

    ... 并滚动到底部,您将看到可以添加允许过滤器的位置:

    即使它说您的主题不支持过滤器,它仍然会改变 API 的行为方式。

    【讨论】:

      【解决方案2】:

      我有同样的问题,产品查询的过滤器参数似乎无效,并将集合中的所有产品返回给我。 我找不到“允许的过滤器”选项。 目前我正在使用 Storefront API 作为外部应用程序,除此之外一切正常。

      这里是代码。

       query (
            $collectionHandle: String, $product_filters: [ProductFilter!], $nQueryElements: Int
          ) {
            collection(handle: $collectionHandle) {
              title
              products(first: $nQueryElements filters: $product_filters) {
                pageInfo {
                  hasNextPage
                  hasPreviousPage
                }
                edges {
                  cursor
                  node {
                    title
                    vendor
                    availableForSale
                    id
                    handle
                    productType
                    variants(first: 40) {
                      edges {
                        node {
                          selectedOptions {
                             name
                            value
                              }
                          title
                          compareAtPriceV2 {
                            amount
                          }
                          image {
                            id
                          }
                        }
                      }
                    }
                    priceRange {
                      maxVariantPrice {
                        amount
                      }
                    }
                    images(first: 1) {
                      edges {
                        node {
                          id
                          url(transform:  { maxWidth: 500, maxHeight: 700 })
                        }
                      }
                    }
                  }
                }
              }
            }
          }
      

      const variables = { collectionHandle: this.pageURL, nQueryElements: this.nQueryElements, lastCursor: this.queryCursor.last, firstCursor: this.queryCursor.first, product__filters: [{ productVendor: "ASPESI", },], } ;

      感谢谁能提供帮助。

      【讨论】:

      • 欢迎来到 SO!您最好使用此信息创建一个新问题,而不是作为原始问题的答案 - 这样您将获得更好的社区帮助。
      猜你喜欢
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 2023-04-11
      • 2014-09-19
      • 2016-04-24
      • 1970-01-01
      • 2011-07-15
      相关资源
      最近更新 更多