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
誰かが私が間違っていることを教えてもらえますか?
ありがとう、アウグスト