简体   繁体   English

使用shopify_api gem更新智能收藏夹中的产品订单时出现文件结尾错误

[英]End of file error while updating product order in smart collection using shopify_api gem

Setting products attribute in the order method for more than 400 products throws following error even before calling collection.save order方法中为超过400种产品设置products属性甚至在调用collection.save之前都会引发以下错误。

 EOFError: end of file reached error 

The documentation says you can send 250 positions. 文档说您可以发送250个职位。 But the order endpoint seams to accept 300 positions successfully. 但是订单端点接缝成功接受了300个头寸。

So, can we set more than 250 product ids in the order? 那么,我们可以在订单中设置250个以上的产品ID吗? Ir is there any limitation on that? 对此有什么限制吗?

And what does that error actually mean? 这个错误实际上意味着什么?

My code: 我的代码:

    collection = ShopifyAPI::SmartCollection.find(8748376382)
    collection.order(products: [9234893,3483448,8783473,"..."])

Answering my own question. 回答我自己的问题。

I think the end of file error is caused beause of some issue occuring because the query URI's length is exceeding 14000 charecters when updating 400 products although PUT request doesn't have any limit on the URI length I just found a way to update more than 300 product by sending the product ids in the body of the put request. 我认为文件错误的结束是由于某些问题而引起的,因为更新400个products时查询URI的长度超过14000个字符,尽管PUT请求对URI的长度没有任何限制,我刚刚找到了一种更新300多个字符的方法通过在放置请求的正文中发送产品ID来获得产品。

Checkout the answer by RehashWayne in Shopify Forum 在Shopify论坛中检查RehashWayne的答案

Edit the file /usr/local/bundle/gems/shopify_api-5.2.2/lib/shopify_api/resources/smart_collection.rb (as of my gem install path) as follows 编辑文件/usr/local/bundle/gems/shopify_api-5.2.2/lib/shopify_api/resources/smart_collection.rb (从我的gem安装路径开始),如下所示

module ShopifyAPI
  class SmartCollection
    def order_products(ids)
      load_attributes_from_response(put(:order, nil, {products: ids}.to_json))
    end
  end
end

Example usage: 用法示例:

sorted_ids = [12345,12346]
collection.order_products(sorted_ids)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM