未返回带有product_id属性的Shopify API变量 [英] Shopify API Variant not being returned with product_id attribute
本文介绍了未返回带有product_id属性的Shopify API变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我使用Shopify Gem访问Shopify API,并注意到简单的ShopifyAPI::Variant.find调用的响应正文中没有返回product_id属性。
1.9.3p194> ShopifyAPI::Variant.find(209901733)
=> #<ShopifyAPI::Variant:0x007fbf7225d3f0 @attributes={"barcode"=>nil, "compare_at_price"=>"198.00", "created_at"=>"2012-03-23T14:11:39+11:00", "fulfillment_service"=>"manual", "grams"=>1000, "id"=>209901733, "inventory_management"=>"shopify", "inventory_policy"=>"deny", "option1"=>"38", "option2"=>"Ivory Mini Twill", "option3"=>nil, "position"=>16, "price"=>"198.00", "requires_shipping"=>true, "sku"=>"3063", "taxable"=>true, "title"=>"38 / Ivory Mini Twill", "updated_at"=>"2013-04-24T10:25:27+10:00", "inventory_quantity"=>2}, @prefix_options={}, @persisted=true>
根据已发布的新文档here,应返回product_id字段。
GET /admin/variants/#{id}.json
Hide Response
HTTP/1.1 200 OK
{
"variant": {
"barcode": "1234_pink",
"compare_at_price": null,
"created_at": "2013-05-01T15:35:21-04:00",
"fulfillment_service": "manual",
"grams": 200,
"id": 808950810,
"inventory_management": "shopify",
"inventory_policy": "continue",
"option1": "Pink",
"option2": null,
"option3": null,
"position": 1,
"price": "199.00",
"product_id": 632910392,
"requires_shipping": true,
"sku": "IPOD2008PINK",
"taxable": true,
"title": "Pink",
"updated_at": "2013-05-01T15:35:21-04:00",
"inventory_quantity": 10
}
}
推荐答案
它在JSON中,但不在从JSON创建的ActiveResource中。原因是变量activeresource:
中的以下代码 self.prefix = "/admin/products/:product_id/"
def self.prefix(options={})
options[:product_id].nil? ? "/admin/" : "/admin/products/#{options[:product_id]}/"
end
如果需要,您可以创建自己的类来获取单例变量:
module ShopifyAPI
class VariantWithProduct < Base
self.prefix = "/admin/"
self.element_name = "variant"
self.collection_name = "variants"
end
end
并使用此类按id:
获取单个变量 ShopifyAPI::VariantWithProduct.find(xxxxxx)
这篇关于未返回带有product_id属性的Shopify API变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文