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 Sunday, March 21, 2010blog comments powered by Disqus