我正在尝试通过Shopify API Gem获得多个产品。
我知道如何一次检索一个产品ShopifyAPI :: Product.find(product_id)。
谢谢!
答案 0 :(得分:1)
以下是一些已经工作了一百万次的代码......
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..."
答案 1 :(得分:0)
尝试:
ShopifyAPI:: Product.find(:all, params: {ids: "1,2,3,4"}) #add other filter as needed....