【问题标题】:End of file error while updating product order in smart collection using shopify_api gem使用 shopify_api gem 更新智能集合中的产品订单时文件错误结束
【发布时间】:2019-07-02 10:38:28
【问题描述】:

order 方法中为超过 400 种产品设置 products 属性会在调用 collection.save 之前引发以下错误

 EOFError: end of file reached error 

文档说您可以发送 250 个职位。但订单端点接缝成功接受 300 个位置。

那么,我们可以在订单中设置超过 250 个产品 ID 吗?对此有什么限制吗?

那个错误到底是什么意思?

我的代码:

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

【问题讨论】:

  • 你能粘贴其余的文件代码吗?这可能是end 语句不匹配的问题。
  • @AnujKhandelwal 如果end 语句有问题,如果我发送 300 product_id 应该不能正常工作吧?
  • 是的@KirubaKaran。添加该评论时,该问题并不存在。
  • 我也面临同样的问题,但是用get,会试试这个技巧

标签: ruby-on-rails shopify shopify-app


【解决方案1】:

回答我自己的问题。

我认为文件结束错误是由于发生了一些问题,因为更新 400 products 时查询 URI 的长度超过 14000 个字符,尽管 PUT 请求对 URI 长度没有任何限制 我刚刚找到了一种通过在 put 请求正文中发送产品 ID 来更新 300 多个产品的方法。

Checkout the answer by RehashWayne in Shopify Forum

编辑文件/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

示例用法:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多