Spree Commerce

Try It Now

Checkout Supports Flexible System of Charges

Posted on June 25, 2009 by Sean Schofield

The edge version of Spree has just been refactored to allow support for a new and improved system of order charges. This recent commit gives you the ability to have an arbitrary number of charges associated with the order. You are no longer restricted to just shipping and tax amounts (although those are still supported as charges now.) This allows your checkout logic to add your own custom fees (and descriptions) if needed.

There is a new rake task which should migrate your existing orders so that they now have shipping and tax charges when applicable. As always, please backup your database before attempting to run the migrations. If you’re running the source you’ll also need to remove the now empty vendor/extensions/tax_calculator directory after your git pull.

This code is very edge so be prepared for a few bumps if you decide to use it. There is at least one known issue and we’ll likely encounter a few more as we go. You may also want to do a search in your custom code for references to tax_amount and ship_amount. These are no longer valid attributes for the order model. If you need the tax or shipping total for something, however, you can do the following:


So now that we can support an arbitrary number of charges, the next task is to support an arbitrary number (and type) of credits. This concept should be relatively easy since a credit is really just the flip side of a charge. Once that is implemented we can finally get to the coupon and discount stuff that we have been planning for a while now.