Designing a Coupon System

I’m racking my brain trying to figure out a good method for a coupon
system for our ecommerce site. Basically We have a variety of
consditions for certain coupons and a variety of effects.

Some examples:

  1. 5% off any order
  2. Free shipping on orders over $50
  3. Free shipping on an order if a product foo is part of the order
  4. 10% off product foo
  5. 5% off entire order if product foo is in the order

So I need to somehow store the properties of a coupon, and validate that
all its conditions are met, and then apply a couple different effects.
I’m a bit baffled about where to go next. I thought of creating a Proc
for conditions and serializing it in the DB, but that makes it hard to
define via an interface and is just plain messy.

Any ideas on how to approach this type of polymorphic complexity?

Well where a particular product (foo) is involved, that information
should probably be included in the products table (eg, two fields:
discount, order_discount). Any other discount should maybe be included
in a discounts table, with some fields representing conditions
(order_greater_than), and some representing the results if those
conditions are met (shipping_discount). You should probably have a
bool to represent whether it can be used in conjunction with other
offers too.

Actually, I’ve just thought, for the product foo, you should probably
have a product_discount_group table with the two fields above which
:has_many => products. That would make it easier to put products into
discount groups.

That’s the best thing I can think of. I’d be interested to see other


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs