Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:53:38+00:00 2026-06-15T23:53:38+00:00

In Rails 3.2.2 I’m trying to create a new Shopify product with multiple variants

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:53:39+00:00Added an answer on June 15, 2026 at 11:53 pm

    I was forgetting to also create the options in the product:

      option1 = ShopifyAPI::Option.new(
        :name     => "first option"
      )
      options << option1
    
      option2 = ShopifyAPI::Option.new(
        :name     => "second option"
      )
      options << option2
    
      option3 = ShopifyAPI::Option.new(
        :name     => "third option"
      )
      options << option3
    
    
        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,
          :options            => options
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails 3.2.2 app, using the most recent shopify gem on github. I've looked at
rails: I have 'create' and 'update' using the same partial '_form' but the url
Rails newbie here, trying to get a new controller working. When I try to
Rails 3.1.2 with mail gem 2.3.0 I'm trying to use ActionMailer with an ActiveModel
Rails 2.3 has an option to add more routes anytime using RouteSet#add_configuration_file. Is it
Rails -v 3.2.3 im using kaminari to do pagination but i keep getting a
Rails 3.1 now requires you to use image_tag when rendering an image using the
Rails 3.1.1 , For using ajax in my application I used remote=>true method on
Rails 3.2.1 app, using the minitest and autotest-rails gems. If I run rake test
Rails 3.2.8, delayed_job (3.0.3), delayed_job_active_record (0.3.3). Using WEBrick. I have an initializer that asynchronously

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.