Shopify / mobile-buy-sdk-ios

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using Apple Pay or their credit card.
MIT License
453 stars 199 forks source link

Inability to Query Products Within Collection #668

Open cocoahero opened 7 years ago

cocoahero commented 7 years ago

A great user feature is the ability to filter products within a collection, for example by tags or a query string.

While doing such a query is currently available on all products within a shop, there doesn't appear to be a way to do this scoped to a collection. The following GraphQL query fails:

{
  node(id: "myCollectionIdentifier") {
    ... on Collection {
      products(first: 10, query: "tag:leather") {
        edges {
          node {
            title
          }
        }
      }
    }
  }
}
dbart01 commented 7 years ago

Thanks for pointing this out. It is a know concern and we are looking into it. I'll keep this issue open to track progress.

alexman03 commented 6 years ago

+1!!! This feature is a must have for stores that have a large number of products! - YandasMusic

ritteraf commented 6 years ago

Any progress on this enhancement request? Updates?

dbrendon commented 6 years ago

Any progress on this issue? I need the ability to filter/query on both collection and product_type.

ohthatsjhall commented 6 years ago

Agree this would be a valuable enhancement, any update on this feature?

ritteraf commented 6 years ago

If anyone's interested, I couldn't wait around any longer for shopify to implement this basic feature, so I wrote some code that "virtually" does the above.

The conditions for this code are as follows:

  1. Your main collections must be smart collections that break down your product catalog using product types.
  2. You implement three tables on your productsViewController for product types, vendors, and tags.

The code follows the following logic:

  1. The user specifies a specific collection from a list you manually provide
  2. The code queries the specified smart collection, and returns the specified product types in that collection
  3. The code then performs a search using the retrieved types, and loads the exact same products as if you loaded the products from the collection.
  4. The code then runs a specific query that pulls collection filter data from all the products returned by your search. This query returns all product vendors and all product tags for all products in your initial search
  5. This data is loaded into the three tables specified in the conditions. The user is now shown all available product types, vendors, and tags for the products in that collection.
  6. The user then selects the filter they want, and a search string is created using the original search parameters, also including the new user specified parameter.
  7. New products are returned, the three tables are reloaded with new filter data from the user search.

Essentially, we're just using the search functionality for products to it's maximum extent, and ignoring the collection query provided by shopify, as it's useless.

If you want the full breakdown and code, just send me a PM.

EricNetsch commented 6 years ago

@cocoahero @dbart01 Just notified the Storefront API team. Will report back soon with any insight

EricNetsch commented 6 years ago

@cocoahero @dbart01 @ritteraf @alexman03 Here is Shopify's API team response:

"I actually spent some time looking into this and chatting with Mina – it appears that our current back-end currently isn't able to support these types of queries. Due to this, unfortunately we won't have any way to support this in the near future.

Sorry to be the bearer of bad news – we're constantly striving to improve the capabilities of the platform, though in this case we are blocked (for now)."

ritteraf commented 6 years ago

@EricNetsch It's more of a convenience than anything Eric. As I mentioned in my earlier post, the search capabilities can handle the requests we're looking to make, it just required a tremendous amount of code to do so. Thanks for looking into it anyways.

sagilevanon commented 4 years ago

Hi, This feature is much needed (and correct me if I'm wrong, it's not really related to this specific repo). We use collections for pre-configured localization and personalization (i.e.: certain users will only see certain collections). When a user searches for a specific item, we want it to be only within the selected collections. Retrieving the entire collection and filtering it out with iteration is too wasteful, and creates an issue with pagination. Any plans for enabling it in the near future?

modermo commented 4 years ago

Any movement on this?

janoschp commented 3 years ago

Helloooo Shopify??

userSV commented 3 years ago

Is there any success on this? I am not even able to search the products in the store (irrespective of the collection).

Below is my query to search products based on the title: static func queryForSearchProducts(limit: Int, after cursor: String? = nil, productLimit: Int = 25, productCursor: String? = nil) -> Storefront.QueryRootQuery { return Storefront.buildQuery { $0 .products(first: Int32(productLimit), after: productCursor, query:"title:dress") { $0 .fragmentForStandardProduct() } } }

It crashes with "Fatal error: field node wasn't queried" in GraphQL.swift file in MobileBuySDK pods.

sagilevanon commented 3 years ago

My gut feeling is that Shopify doesn't want to release this feature because of a business requirement, not a tech one. We ended up with a quirky and ineffective code just to implement such a simple functionality.

userSV commented 3 years ago

@sagilevanon so are you able to implement the searching of products irrespective of the collection? Can you show me how to implement this.

baseddb commented 2 years ago

@ritteraf or @sagilevanon Would you guys be so free as to share your code solution with us/me?

sagilevanon commented 2 years ago

The solution is basically duplicating title and description to a separated DB and search over it. The DB will hold the Shopify product key and then you can use the products API to fetch those specific items.

On Mon, Jan 3, 2022, 18:51 baseddb @.***> wrote:

@ritteraf https://github.com/ritteraf or @sagilevanon https://github.com/sagilevanon Would you guys be so free as to share your code solution with us/me?

— Reply to this email directly, view it on GitHub https://github.com/Shopify/mobile-buy-sdk-ios/issues/668#issuecomment-1004220670, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJV7PHQTQJKXYROVVEVI3ATUUHHZHANCNFSM4DRACU2A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>