How to get multiple products with product ids through Shopify API Gem

江枫思渺然 提交于 2020-02-07 06:01:19

问题


I'm trying to get multiple products through Shopify API Gem.

I know how to retrieve one product at a time ShopifyAPI::Product.find(product_id).

Thanks!


回答1:


Here is some code that has worked for a million times over ...

page = 1
count = ShopifyAPI::Product.count
puts "Found #{count} products in Shopify"
if count > 0
  product_details = []
  page += count.divmod(250).first
  while page > 0
    products = ShopifyAPI::Product.find(:all, params: {limit: 250, page: page})
    product_details += products.collect {|p| {id: p.id, title: p.title, handle: p.handle, product_type: p.product_type}}
    page -= 1
  end
end
puts "Processing #{product_details.length} products from Shopify..."



回答2:


Try:

ShopifyAPI:: Product.find(:all, params: {ids: "1,2,3,4"}) #add other filter as needed....


来源:https://stackoverflow.com/questions/25459275/how-to-get-multiple-products-with-product-ids-through-shopify-api-gem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!