In Rails 3.2.2 I'm trying to create a new Shopify product with multiple variants using the Rails Shopify Gem 3.0.1.
Everything works with just 1 option, however if I try to use 2 options in my variants the product gives an error on save:
#<ActiveResource::ResourceInvalid: Failed. Response code = 422. Response message = Unprocessable Entity.>, @validation_context=nil, @errors=#<ActiveResource::Errors:0x0000010297a5b0 ...>>, @messages={:base=>["Options are not unique"]}>
Here is my code:
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
The strange thing is that the product get saved if I remove the 5th variant (the one that has still "-s-" as option1), gives error if I try to create all the 5 variants.
Can you please give me some advise on what I am doing wrong?
Thanks in advance, Augusto
@messages={:base=>["Options are not unique"]}
" It seems that ActiveResources wants only unique options. Have you looked into that? – MrYoshiji