Shopify API 发生了一些奇怪的事情,我无法理解我做错了什么。
我想从 Shopify 获取所有产品的列表,因此我使用以下代码:
def get_all_products_from_shopify
limit = 250
all_products = Array.new
self.connect_to_store
products = ShopifyAPI::Product.find(:all, :params => {:limit => limit})
all_products = all_products.concat products
puts products.length
while products.length == limit do
since_id = products.last.id
products = ShopifyAPI::Product.find(:all, :params => {:limit => limit, :since_id => since_id})
all_products = all_products.concat products
end
ShopifyAPI::Base.site = nil
return all_products
end
问题是我在 Shopify 上有 251 种产品,但是通过这种方法,我检索了一个包含 277 个元素的产品数组。为什么?
另外,如果我这样做:
products = ShopifyAPI::Product.count
> 251
products = ShopifyAPI::Product.find(:all, :params => {:limit => limit})
products.count
>250
since_id = products.last.id
ShopifyAPI::Product.count(since_id: since_id)
>26
谁能告诉我我做错了什么?
谢谢,奥古斯托