Spree Commerce

Try It Now

New on Edge: Coupons

Posted on August 17, 2009 by Sean Schofield

Coupons have finally arrived in the latest (edge) version of the source code. We are still working out a few of the bugs but the code is stable enough that it has been merged into the core and is ready to be used for those with an urgent need.

Eligibility

Coupon eligibility is completely customizable on a per coupon basis. Eligibility is determined by the following factors.

  • Start Date – coupons can be configured to be invalid before a specific date
  • Expiration Date – coupons can be configured so that they are not usable passed a certain date
  • Expiration Date – coupons can be configured so that they are not usable passed a certain date
  • Number of Uses – coupons can be restricted to an arbitrary number of uses (typically a single use if there’s a limit at all)
  • Combination – there is an option to restrict specific coupons so that they cannot be combined with other coupons in the same order.

Any other restriction on eligibility is intended to be provided by custom calculators. The compute method has access to the complete order (including shipping and other related information) and can simply return nil if the coupon is not to be applied in a specific situation

Discount Calculation

The create_discount method in Coupon is responsible for the actual calculation of the credit to be applied for the cooupon. By default, Spree will not allow the credit amount to exceed the item total. The credit adjustment associated with a coupon is subject to recalculation based on changes in the order. This is no different then any other adjustment to the order total (such as shipping or tax charges.)

This is just the initial set of features we’re planning on supporting. Coupons will be part of the upcoming 0.9.0 release in September. You can expect additional improvements and third party calculators to follow shortly thereafter.