Search code examples
ruby-on-railsshopifyshopify-app

Fetch products which are available online - Shopify


I'm building a Shopify app using Rails. I want to fetch the products which are only available online from the Collections

I have the following code to fetch the products but it returns all the products even if they are not available online

ShopifyAPI::SmartCollection.find(collection_id).products

How to pass the conditions for products?


Solution

  • According to the Shopify API Reference, you can pass a published_status and collection_id parameters to your Api call to retrieve published products from a specific colleciton.

    Using the Ruby library it gives:

    ShopifyAPI::Product.find(:all, params: { published_status: 'published', collection_id: collection_id })
    

    Hope it helps