【发布时间】:2012-12-04 16:26:31
【问题描述】:
在 Rails 3.2.2 中,我尝试使用 Rails Shopify Gem 3.0.1 创建具有多个变体的新 Shopify 产品。
一切都只使用 1 个选项,但是如果我尝试在我的变体中使用 2 个选项,产品会在保存时出错:
#<ActiveResource::ResourceInvalid: Failed. Response code = 422. Response message = Unprocessable Entity.>, @validation_context=nil, @errors=#<ActiveResource::Errors:0x0000010297a5b0 ...>>, @messages={:base=>["Options are not unique"]}>
这是我的代码:
variants = []
variant = ShopifyAPI::Variant.new(
:option1 => "-s-",
:option2 => "azul",
:option3 => "boxer",
:inventory_management => "shopify",
:inventory_quantity => 350
)
variants << variant
variant = ShopifyAPI::Variant.new(
:option1 => "-m-",
:option2 => "azul",
:option3 => "boxer",
:inventory_management => "shopify",
:inventory_quantity => 495
)
variants << variant
variant = ShopifyAPI::Variant.new(
:option1 => "-l-",
:option2 => "azul",
:option3 => "boxer",
:inventory_management => "shopify",
:inventory_quantity => 543
)
variants << variant
variant = ShopifyAPI::Variant.new(
:option1 => "-xl-",
:option2 => "azul",
:option3 => "boxer",
:inventory_management => "shopify",
:inventory_quantity => 425
)
variants << variant
variant = ShopifyAPI::Variant.new(
:option1 => "-s-",
:option2 => "negro",
:option3 => "boxer",
:inventory_management => "shopify",
:inventory_quantity => 778
)
variants << variant
product = ShopifyAPI::Product.new(
:title => original_p.title,
:product_type => original_p.product_type,
:handle => original_p.handle,
:vendor => original_p.vendor,
:body_html => original_p.body_html,
:template_suffix => original_p.template_suffix,
:tags => original_p.tags,
:variants => variants
)
product.save
奇怪的是,如果我删除第 5 个变体(选项 1 仍为“-s-”的那个),产品会被保存,如果我尝试创建所有 5 个变体,则会出错。
您能否就我做错了什么给我一些建议?
提前致谢, 奥古斯托
【问题讨论】:
-
"
@messages={:base=>["Options are not unique"]}" 似乎 ActiveResources 只需要独特的选项。你调查过吗? -
事实上这似乎是个问题,但 Shopify - 至少来自网络管理员 - 确实允许创建具有 3 种不同选项(尺寸、颜色、适合度)的产品,并允许同时拥有 2 种不同的变体尺寸小但颜色不同。 API 是否有比网络管理员更严格的限制?
标签: ruby-on-rails ruby-on-rails-3 shopify