我在通过shopify_api gem完成订单中的订单项时遇到问题。当我履行单个订单项时,它会履行订单中的所有订单项。我已经调查了一下,人们说了一些关于设置标题的内容,请清楚。
我正在做的是
order = ShopifyAPI::Order.find(order_id)
假设此订单包含多个订单项
f = ShopifyAPI::Fulfillment.new(:params => { :order_id => order.id, :line_items => [ {"id" => order.line_items.first.id} ] })
f.prefix_options = { :order_id => order.id }
f.save
这段代码履行了订单中的所有订单项,并将履行状态设置为已满足,这是不可取的。
以下是标题,履行对象和tcpdump的详细信息:
Shopify标题
(rdb:1) p ShopifyAPI::Fulfillment.headers
{"User-Agent"=>"ShopifyAPI/3.0.1 ActiveResource/3.1.1 Ruby/1.9.2", "X-Shopify-Access-Token"=>"be9d4adaa35e7f82b720a3567250424c"}
履行对象
#<ShopifyAPI::Fulfillment:0xca2086c @attributes={"params"=>#<ShopifyAPI::Fulfillment::Params:0xca20b00 @attributes={"order_id"=>138494648, "notify_customer"=>true, "tracking_number"=>"12345678", "line_items"=>[#<ShopifyAPI::LineItem:0xca28904 @attributes={"id"=>225568082}, @prefix_options={}, @persisted=false>]}, @prefix_options={}, @persisted=false>}, @prefix_options={:order_id=>138494648}, @persisted=false>
tcpdump输出
10:07:14.498936 IP localhost.localdomain.34941&gt; localhost.localdomain.domain:50737+ AAAA? olson-pfeffer-and-ratke1494.myshopify.com。 (59)
E..W .. @。@。D ..........}。5.CV1 ........... olson-pfeffer-and-ratke1494 myshopify.com .. ...
10:07:14.655477 IP localhost.localdomain.domain&gt; localhost.localdomain.34941:50737 1/1/0 CNAME shops.shopify.com。 (160)
Ë..... @。@。1 ....... X。 :....&LT;
10:07:14.655650 IP localhost.localdomain.36871&gt; localhost.localdomain.domain:39864+ A? olson-pfeffer-and-ratke1494.myshopify.com。 (59)
E..W .. @。@。D ............ 5.CV ............ olson-pfeffer-and-ratke1494 myshopify.com .. ...
10:07:14.948404 IP localhost.localdomain.domain&gt; localhost.localdomain.36871:39864 5/4/4 CNAME shops.shopify.com。,A 204.93.213.40,A 204.93.213.41,A 204.93.213.42,A 204.93.213.44(301)
E..I .. @。@。; .......... 5 ... 5.H ............. olson-pfeffer-and-ratke1494 myshopify。 COM .............. X ... shops.shopify.2.G ....... X ...]。(:G ....... X ...])... G ....... X ...]。*:G ....... X ...],... M .......... .ns3.p19.dynect.net..M ........... NS4 ...,M ........... NS1 ...,M ....... .... NS2 .......... 0 .... NF ................. 0 .... NG ...... ... 0 ....
10:07:16.326985 IP6 geek-laptop.46193&gt; geek-laptop.46193:UDP,长度16
...... @ ................................. qq.j ....... ...... .. 6K
10:07:16.338153 IP6 geek-laptop.46193&gt; geek-laptop.46193:UDP,长度20
......@.................................q.q../#........).....!.6k..
10:07:16.340185 IP6 geek-laptop.46193 > geek-laptop.46193: UDP, length 16
...... @ ................................. qq..G。 .........!6K ..
10:07:16.350974 IP6 geek-laptop.46193&gt; geek-laptop.46193:UDP,长度924
`...... @ ................................. qq.tk ...... ..)...... ............................................ .................................................. 。“.......“.......F
.................................................. .................................................. .................................................. ................................................C
.................................................. ................................................ 2
.................................................. ................................................ w ^
.................................................. ................................................)
.................................................. ................................................ 8 < / p>
答案 0 :(得分:4)
实际问题是,当您创建履行时,您将:params => hash_of_fulfillment_data
传递给new
方法。只需传递数据,您就不需要params键。这只是标准的ActiveResource,没什么特别的。这应该有效:
f = ShopifyAPI::Fulfillment.new(:order_id => order.id, :line_items =>[ {"id" => order.line_items.first.id} ] )
f.prefix_options = { :order_id => order.id }
f.save