One-off/user-customized products in Spree
One of our clients sells customizable products. He contracted us to write a webapp to facilitate the process for his customers. We decided to go with Spree for the integrated eCommerce and order fulfillment capabilities. Having written eCommerce implementations before…

… Spree sounded like a much better option.
The trick then became how we would represent these user customized products. As it turns out, Spree supports this in the model out of the box. In Spree, products are represented by instances of the Product class. However, they can also be represented by Variants of a Product. That is, a Product has many Variants. Variants can vary by price but they also can vary by OptionValues.
I know: OptionValues is quite a mouthful of generic stuff.

But they’re useful! Let me explain.
In Spree, a Product can have multiple OptionTypes. Each OptionType describes what amounts to a container for an enumeration. The OptionType then has OptionValues. These OptionValues are the values in that enumeration. And Variants have many OptionValues.
When you put it all together, it looks something like this:
Now that is one tasty burger!
The only downside that I see is that, for one-off/user-customized products, at a minimum, you will be creating a Variant with permutations of OptionValues for each line item in a user’s order containing a customized product resulting in a cluttered products table. If you’re willing to do a little extra work, you could probably elaborate upon the Spree model to determine if a Variant already exists with your desired permutation of OptionValues before going off and creating one.
So there you have it.
Posted by evan on Mar 21, 2010
My name is Evan Light and, yes, I am a nerd. I'm also a professional software developer who, after spending one too many years contracting to the federal government, escaped into the far more enjoyable commercial world. Having spent several years using C and even more using Java (the latter very nearly caused me to give up programming entirely), I consider myself fortunate to have discovered Ruby and to use it as part of my daily work.