Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature - create a product with variants from a hash of option types & values #1189

Closed
wants to merge 5 commits into from

Conversation

citrus
Copy link
Contributor

@citrus citrus commented Feb 24, 2012

This pull request adds the ability to create variants for products from a hash of option_types and option_values. Basically you can do something like this:

rails console
size = Spree::OptionType.create(:name => "size", :presentation => "Size")
%w(Small Medium Large).each do |name|
  size.option_values.create(:name => name.downcase, :presentation => name)
end

color = Spree::OptionType.create(:name => "color", :presentation => "Color")
%w(Red White).each do |name|
  color.option_values.create(:name => name.downcase, :presentation => name)
end

options = {}
Spree::OptionType.all.each do |ot|
  options[ot.id.to_s] = ot.option_value_ids
end

puts options
#=> {"1"=>[1, 2, 3], "2"=>[4, 5]}

product = Spree::Product.create(:name => "Zomg!", :price => 5, :option_values_hash => options)

puts product.variants.count
#=> 6

Why?!

...so we can create new products & variants from prototypes! Once you select a prototype from the new product page you'll get a group of checkboxes for each option type and it's option values. Select whichever type/value combo you'd like then click create. Now visit the product variants page and see your newly created variants.

If you'd like to see it in action, just check out the video:

http://vimeo.com/37367111

Specs are included and all are passing 🍺 🍺

@moladukes
Copy link
Contributor

This will save lots of time during multiple product creation! Instead of having to manually create the variants over and over. You basically create it once in prototypes and boom! Nice work!

@citrus
Copy link
Contributor Author

citrus commented Feb 29, 2012

Any feedback on this? 👎 👍

\cc @schof @BDQ @radar

Thanks!! :)

@BDQ
Copy link
Member

BDQ commented Feb 29, 2012

Yeah it get's my vote for merge for sure.

@sbounmy
Copy link
Contributor

sbounmy commented Feb 29, 2012

Nice ! +1 👍

@BDQ
Copy link
Member

BDQ commented Mar 1, 2012

Merged, thanks for the contribution.

@BDQ BDQ closed this Mar 1, 2012
@citrus
Copy link
Contributor Author

citrus commented Mar 1, 2012

Awesome thanks @BDQ! 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants