![](/img/trans.png)
[英]Rails 2.3: Product has_many Variants - how to do find on Product with conditions on Variant?
[英]How to create a shopify product with many variants
任何人都知道如何使用變體創建新產品?
在Ruby on Rails世界中,我們有:has_many
,然后執行以下操作:
Product.create!(...).variants.build(...).save
這將創建一個產品及其關聯variant
。
對於Shopify,我不知道:
user_products.map do | up |
new_products = ShopifyAPI::Product.build(...)
up.variants.each do |variant|
new_products.variants.build(...)
end
new_products.save
end
做到這一點我得到了:
ActiveResource :: ServerError(失敗。響應代碼= 501.響應消息=未實現。)
就我而言,這並不理想:
ShopifyAPI::Product.new(
{
...,
variants: [
...
]
}
).save
Shopify不支持變體作為嵌套對象。 您需要為每個要創建的變體創建REST請求。 請參閱變體對象文檔
適用於變體的Shopify API: https ://help.shopify.com/api/reference/product_variant
並且還要確保您使用Shopify gem: https : //github.com/Shopify/shopify_api
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.